我有一个触发以下代码的计时器。如果需要出示通知,我需要出示表格。问题是当线程在线程内部被触发并且我设置ConfiguracioGlobal.DicNotices[kvp.Key].Shown = true;
下一次运行时不知道这.Shown
是真的。显示表单时出现以下错误:Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
我想我必须使用委托,但我不知道:(
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate
{
try
{
foreach (KeyValuePair<int, Notice> kvp in GlobalConfiguration.DicNotices)
{
if (!kvp.Value.Shown && DateTime.Now.Hour == kvp.Value.HourIni.Hour && DateTime.Now.Minute == kvp.Value.HourIni.Minute)
{
GlobalConfiguration.DicNotices[kvp.Key].Shown = true;
FrmNotices frmPopup = new FrmNotices(kvp.Key);
frmPopup.Show();
Application.Run(frmPopup);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error");
}
}));
thread.IsBackground = true;
thread.Start();
任何想法?谢谢大家。