在我的應用程序中,我有要求通知用戶有關未決應用程序的要求。跨線程操作無效:
所以在mdiParent
我設置BackgroundWorker
這使查詢數據庫得到任何未決申請,如果發現任何顯示它的工具提示上MdiParent
private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync(2000);
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
fillnotification();
}
public void fillnotification()
{
int pending = 0;
if(Program.USERPK != 0)
{
DataTable dt = nftrans.getnotification();
pending = dt.Rows.Count;
String message = "You Have " + pending + " Applications Pending For Approval";
// toolTip1.SetToolTip(lblStatus , message);
toolTip1.Show(message , this, lblStatus.Location);
}
}
但是當我運行的解決方案,我我得到一個例外:
跨線程操作無效:控制'MainForm'從一個線程以外的線程訪問它創建的線程。
我明白它由於兩個不同的線程,但不能整理出來。任何人都可以提出解決方案嗎?我嘗試了我在相關問題中閱讀的想法但找不到正確的解決方案
是那些Win Forms? – 2013-05-11 05:57:18
是的winform應用程序 – 2013-05-11 06:13:41
[請參閱我的答案](http://stackoverflow.com/questions/11273562/c-sharp-cross-thread-communication/11274317#11274317) – 2013-05-11 07:11:18