By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

threading problem

P: n/a
i try to implement simple threading im my application and i get this error
message :

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.windows.forms.dll
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.

on this line on one of two threads that i have in my application:
tree.Nodes.Add(Nodex)
TreeView is declared on form not on current thread. Why, any ideas? Any
examples any ideas Any help anything
THX
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Dzemo" <dz***@wizard.ba> schrieb:
An unhandled exception of type 'System.InvalidOperationException' occurred
in system.windows.forms.dll
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.

on this line on one of two threads that i have in my application:
tree.Nodes.Add(Nodex)
TreeView is declared on form not on current thread. Why, any ideas?


You must not access instance members of Windows Forms controls from another
thread because they are not safe for multithreading.

Multithreading in Windows Forms applications
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=en>

\\\
Private Delegate Function AddDelegate( _
ByVal text As String _
) As TreeNode

Private Sub DoWork()
Me.TreeView1.Invoke( _
New AddDelegate(AddressOf Me.TreeView1.Nodes.Add), _
New Object() {"Bla"} _
)
End Sub
..
..
..
Dim th As New Thread(AddressOf DoWork)
th.Start()
///

Related: 'Control.InvokeRequired'/'Control.BeginInvoke'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.