c# - Controlling form elements from a different thread in Windows Mobile -
Windows Mobile is trying to get a thread to change form controls.
Throws an unsupported exception. / P>
Does this mean it can not be done at all?
If not, how do I know about it? If the form is made in the original / main thread, then a thread is created to do some work in the background, but I want to make it so that it can update the background thread to update the form ...
< / Div>
You can not access GUI items on the non-GUI thread. You will need to determine whether a charge is required for the GUI thread. For example (here's something I did before):
Public Representative Zero SetEnabledStateCallBack (Control Control, Boole Enabled); Public Static Zero SetEnabledState (Control Control, Bowl Enabled) {If (control.InvokeRequired) {SetEnabledStateCallBack D = New SetEnabledStateCallBack (SetEnabledState); Control.Invoke (D, New Object [] {Control, Enabled}); } Else {control.Enabled = enabled; }}
or
Public Rep Zero AddListViewItemCallBack (ListView Control, ListViewItem Item); Public Static Zero AddListViewItem (ListView Control, ListViewItem Item) {if (control.InvokeRequired) {AddListViewItemCallBack D = New AddListViewItemCallBack (AddListViewItem); Control.Invoke (D, new object [] {control, item}); } And {control.Items.Add (item); }}
You can set the property capable (using my first example) using ClassName.SetEnabledState (this, true); .
Comments
Post a Comment