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