跨线程操作无效:控制从其创建的线程以外的线程访问的“treeview”。 [英] Cross-thread operation not valid: control 'treeview' accessed from a thread other than the thread it was created on.

查看:85
本文介绍了跨线程操作无效:控制从其创建的线程以外的线程访问的“treeview”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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





我是什么尝试过:



尝试过使用处理程序但是d idnt为我工作



What I have tried:

have tried using handlers but that didnt worked for me

推荐答案

错误很明确:你只能从UI线程访问控件 - 你的代码没有在UI线程上运行所以你不能直接访问控件。

要做到这一点,你需要调用控件: Control.Invoke方法(委托)(System.Windows.Forms) [ ^ ]
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)[^]


这篇关于跨线程操作无效:控制从其创建的线程以外的线程访问的“treeview”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆