C#: how to update winform from thread?

Posted by JackN on Stack Overflow See other posts from Stack Overflow or by JackN
Published on 2010-12-27T18:38:45Z Indexed on 2010/12/27 18:54 UTC
Read the original article Hit count: 266

Filed under:
|

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;
    ...

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms