这是好主意,用" Control.CheckForIllegalCrossThreadCalls = FALSE" [英] Is it good idea to use "Control.CheckForIllegalCrossThreadCalls = false"

查看:1173
本文介绍了这是好主意,用" Control.CheckForIllegalCrossThreadCalls = FALSE"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的serialport从接收数据的类。我用动作< T>代表将数据传递给它显示在一个文本框的形式。事情是我不能访问文本控制,becouse它说:跨线程操作无效:控制距离小于线程以外的线程访问它是在创建。

I have a class that receives data from serialport. i used action<T> delegate to pass data to the form where it is displayed in a textbox. the thing is i could not access the textbox control, becouse it says: Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on.

所以我设置 Control.CheckForIllegalCrossThreadCalls = FALSE ,和这是工作。

so i set Control.CheckForIllegalCrossThreadCalls = false, and it is working.

是好主意,这样做呢?或者有这样做的更好的方法。

is it good idea to do that? or there is a better way of doing it.

感谢

推荐答案

虽然它可能会出现工作的大部分时间,这是肯定现在再失败每一个。

While it may appear to work most of the time, it is sure to fail every now and then.

如果你需要从另一个线程访问/修改UI控件,使用 Control.Invoke

If you need to access/modify the UI control from another thread, use Control.Invoke.

这篇关于这是好主意,用&QUOT; Control.CheckForIllegalCrossThreadCalls = FALSE&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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