0

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;
    ...
jacknad
  • 13,483
  • 40
  • 124
  • 194
  • 2
    Check this question http://stackoverflow.com/questions/661561/how-to-update-gui-from-another-thread-in-c – Gratzy Dec 27 '10 at 18:41
  • You should look into installing System_SR_ENU_wm.CAB or something similar that will enable you to get the error messages on your platform. To save space they usually don't include all the error messages on devices. – dwidel Dec 27 '10 at 18:58
  • 1
    The anonymous method by Marc Gravell in Gratzy's link (http://stackoverflow.com/questions/661561/how-to-update-gui-from-another-thread-in-c/661662) seemed to be the simplest solution for this problem. this.Invoke((MethodInvoker)delegate { someLabel.Text = newText; // runs on UI thread }); – jacknad Dec 27 '10 at 19:59

2 Answers2

4

You'll need to use Invoke to make changes to controls created in the Gui Thread.

To make life easier, take a look at some of the extension methods provided here

Community
  • 1
  • 1
Brook
  • 5,949
  • 3
  • 31
  • 45
2

You should call Control.BeginInvoke

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964