C#: how to update winform from thread?
- by JackN
A C# thread (Read()) causes System.NotSupportedException when it tries to update a winform based on received content.
The full error message is
Read() System.NotSupportedException:
An error message cannot be displayed
because an optional resource assembly
containing it cannot be found at
Microsoft.AGL.Common.MISC.HandelAr()
at
System.Windows.Forms.ProgressBar._SetInfo()
at
System.Windows.Forms.ProgressBar.set_Value()
at ...ProcessStatus() at ...Read()
The Build/Target Environment is: Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE. Is the problem writing to the ProgressBar from a Thread?
If so, what is the correct C#/winforms method to update a ProgressBar from a Thread? In this application the Read() Thread is continuous: it is started when the application starts and runs forever.
void ProcessStatus(byte[] status)
{
Status.Speed = status[5];
var Speed = Status.Speed/GEAR_RATIO;
Status.Speed = (int) Speed;
progressBarSpeed.Value = Status.Speed;
...