그래서 작은 Twitter 클라이언트를 쓰고 있습니다. 나는 하나의 커다란 패널과 개별 트윗을 나타내는 작은 패널의 조합을 사용하고있다. 더 작은 각각의 패널에는 PictureBox와 RichTextBox가 있습니다.BackgroundWorker의 컨트롤로 패널 채우기
내 문제는 동적으로 패널을 생성하기 때문에 10 개 이상의 트윗을로드하면 속도가 느려지 게된다는 것입니다. 그래서 BackgroundWorker를 사용하여이 작업을 수행 한 다음이 패널을 기본 패널에 추가하기로 결정했습니다.
저는이 텍스트를 다른 thead의 텍스트 상자에 쓰는 것을 여러 번했습니다 (자습서도 썼습니다). 그러나 나는 이것을 작동시킬 수 없다.
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
코드 :
List<Panel> panelList = new List<Panel>();
foreach (UserStatus friendStatus in list)
{
PictureBox pbTweet = new PictureBox();
// ...
// code to set numerous properties
// ...
RichTextBox rtbTweet = new RichTextBox();
// ...
// code to set numerous properties
// ...
Panel panelTweet = new Panel();
// ...
// code to set numerous properties
// ...
panelTweet.Controls.Add(pbTweet);
panelTweet.Controls.Add(rtbTweet);
panelList.Add(panelTweet);
}
if (panelMain.InvokeRequired)
panelMain.BeginInvoke((MethodInvoker)delegate { foreach (Panel p in panelList) { panelMain.Controls.Add(p); } });
누구나 어떤 문제가 나타날 나는 오류 메시지가?
어떤 줄이 오류를 던지고 있습니까? –
BeginInvoke 메서드는 foreach를 수행 할 때 오류를 throw합니다. –