在我的应用程序中,我有要求通知用户有关未决应用程序的要求。跨线程操作无效:
所以在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