-
TreeView problem
Every time I try to add a node to a tree view I get the following message:
Code:
Additional information: 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 have not threaded this project, my add method is being called from a private sub.
Any ideas??
Thanks!
-
Where is the code located?
A .Net control is private to the Form that it is placed so you can't add nodes in a Sub that doesn't belong to the Form.
-
This error message you get tipically when you call a method on a control from other than the UI thread. You said you don't write multi threaded code in that app, but there are scenarios when the runtime creates new threads implicitly for you, with Async Delegates for example. So first try to find out if that's the case, by getting the HashCode of the CurrentThread (C#: MessageBox.Show(Thread.CurrentThread.GetHashCode().ToString()); )
If this is the case you should use Invoke or BeginInvoke.
(BeginInvoke = Async and Invoke = Sync)
-
The code is in an event of another control, all on the same form. It did tell me I need to use the begin invoke method (Visual Basic) however, there are no examples on how do do that.
Thanks for the help!!