如何访问在不同线程上运行的窗体上的控件 [英] How Do I Access A Control On A Form Which Running On Different Thread

查看:96
本文介绍了如何访问在不同线程上运行的窗体上的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个表单上访问椭圆形状,从一个在不同线程上运行的类,通过委托传递一个方法,允许更改椭圆的宽度..但每当我尝试调用那个方法时,它给我一个例外,说无效的操作异常。

I'm trying to access "ellipse" shape on a form,from a class which is running on a different thread by passing a method via delegate which allows to change ellipse' width ..but whenever i try to call that mnethod , it gives me a exception saying "Invalid Operation Exception".

推荐答案

您可以使用UI调用机制。请查看我过去的答案:

问题Treeview扫描仪和MD5 [ ^ ],

Control.Invoke()与Control.BeginInvoke() [ ^ ]。



-SA
You can use UI invocation mechanism. Please see my past answers:
Problem with Treeview Scanner And MD5[^],
Control.Invoke() vs. Control.BeginInvoke()[^].

—SA

这篇关于如何访问在不同线程上运行的窗体上的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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