c# - Changing controls in a thread safe manner -


I'm trying to use threadsfor calls with UI controls from the UI controls. BackgroundWorkerHelper is not available for some reason, maybe due to the version of C # or becuase, I'm positioned on "Window CE 5.0 Device".

I have this

  // Thredsef gets asked to edit the components for personal representatives zero SetControlPropertyThreadSafeDelegate (Control, String propertyName, object propertyValue); public static void SetControlPropertyThreadSafe (Control, String property, objected propertyValue) {if (control.InvokeRequired) {control.Invoke (New SetControlPropertyThreadSafeDelegate (SetControlPropertyThreadSafe), new object [] {control, property, propertyValue}); } Else {control.GetType (). InvokeMember (Property Name, Binding Flex. Setup, blank, Control, New Object [] {propertyValue}); }}   

and calling such threads

  private thread worker thread = new Thread (new Thredstart (this.remoteRequestBackgroundTask)); WorkerThread.Start ();   

Then remoteRequestBackgroundTask () function I changed in such control

  // Cancel button enabled SetControlPropertyThreadSafe (btnCancel, "enable", true);   

The problem is that when it runs, debugging stops

  control.GetType (). InvokeMember (propertyName, BindingFlags.SetProperty, null, control, new object [] (propertyValue));   

And I get "Not SupportedException" is

A look enter further exception under not SupportedException , you'll see:

.NET compact Framework currently this method does not support .

In that else block, I believe that you can do something like this instead. This is something very similar to the NET compact framework code I have:.

  PropertyInfo PropertyInfo = control.GetType () getProperty (property); PropertyInfo.SetValue (control, property value, blank);    

Comments