Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
On client I have a tree node on right click on deploy command which publishes a file to my  server.
So on clicking the tree node I will check if the tree ode name is the same as of file name if same ok else I will try to update the object name through server reply. Which here means I have got the server reply and trying to setting the "Text" but at the time of setting the text here in my case :

BaseObject.GetNodeText(Me.QueryConfig)

 Is getting executed and throwing me error 
"Cross-thread operation not valid: Control 'Treeview' accessed from a thread other than the thread it was created on
"

If Not OverrideDefaultDisplayText Then
                    Text = BaseObject.GetNodeText(Me.QueryConfig)
                Else
                    Text = BaseObject.GUIDisplayAs
                End If

this all happens inside a method called refresh


Can someone please suggest what I need to do



Error:
Cross-thread operation not valid: Control 'Treeview' accessed from a thread other than the thread it was created on


What I have tried:

have tried using handlers but that didnt worked for me
Posted
Updated 19-Mar-18 6:11am
v2

1 solution

The error is pretty explicit: you can only ever access controls from the UI thread - your code is not running on the UI thread so you cannot directly access the control.
To do that, you need to Invoke the control: Control.Invoke Method (Delegate) (System.Windows.Forms)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900