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
  • 12,983
  • 39
  • 119
  • 191
  • 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,859
  • 3
  • 30
  • 45
2

You should call Control.BeginInvoke

SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933