1
Answer

Threading, Events and UI Update

I start a lengthy process using a worker thread from my main form. Form frmMain Fields... Private WithEvents run as New CRun Private tRun as Threading.Thread() Here's how I kick off the thread... tRun = New Threading.Thread(AddressOf run.Run) tRun.Start() I use events in the Run method of the run object to communicate it's progress back to the UI. In each event handler on frmMain I update a label's text property so that the user knows how the processing is progressing. The program experiences no problems whatsoever when doing this. When the processing completes the Run method raises a RunComplete() event. I try to update a treeview control in the event handler but I get the following error message: The action being performed on this control is being called from the wrong thread. You must marshal to the correct thread using Control.Invoke or Control.BeginInvoke to perform this action. I could understand getting this error message if I was trying to update the treeview directly from the worker thread but I am updating the treeview from an event handler in the main form. Also the fact that the label control is being updated with no problems in the other event handlers seems odd. Who don't I get the same error message when I do that? Can anybody give me some insight as to what's going on? Thanks in advance.
Answers (1)
Next Recommended Forum