Possible Duplicate:
Why am I getting this error:“Cross-thread operation not valid: Control lbFolders accessed from a thread other than the thread it was created on.”?
Invoke or BeginInvoke cannot be called on a control until the window handle has been created跨线程操作无效
我有线程问题。
我每隔600毫秒从COM端口获取数据,当我处于调试模式时,出现几秒钟后出现错误,但是当我处于非调试运行模式时,我在一两分钟后出错,但错误持续。
我得到的错误发生在每个线程上调用的某些函数上。
以下是错误的图片:
代码的其他部分:
private void LoadData()
{
while (td.IsAlive)
{
eng.GetSpeedKmh();
eng.GetEngineRpm();
eng.GetCalculatedEngineLoadValue();
eng.GetFuelLevelInput();
eng.GetEngineTemp();
eng.MAF();
System.Threading.Thread.Sleep(600);
}
}
我能做些什么来解决这个问题?
【如何:使线程安全的调用到Windows窗体控件(http://msdn.microsoft.com/en-us/library/ms171728(V = VS。 80).aspx) –
错误信息告诉你一切你可能想知道的。 –
@DavidSchwartz:我想他们也想知道如何解决这个问题。 – Jon