交叉线不能在一个表格上发生两次 [英] Crossthreading cant happen twice on one form

查看:73
本文介绍了交叉线不能在一个表格上发生两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在一张表格上运行了2个tcpclients。



收到一张图片把它放在图片盒中



一个人收到正常的信息,然后在后台处理它们(怎么没必要)。



问题是图片框只是更新,如果它在一个代码只包含一个tcpclient的表单上



但我想要一个表单来控制多个tcpclients。





我该怎么做?

Hi,

I have 2 tcpclients running on one form.

One receives an image and puts it in the picturebox

One receives normal messages and just processes them in the background (how is unnecessary).

The problem is that the picturebox is only updates if its on a form that has code that only contains one tcpclient

But i want one form to control multiple tcpclients.


How do i do this?

推荐答案

您不能从非UI线程调用与UI相关的任何内容。相反,您需要使用 Invoke System.Windows.Threading的方法。 Dispatcher (对于Forms或WPF)或 System.Windows.Forms.Control (仅限表单)。



您将在我过去的答案中找到有关其工作原理和代码示例的详细说明:

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

使用Treeview扫描仪和MD5的问题 [ ^ ]。



另请参阅有关线程的更多参考资料:

如何让keydown事件在不同的操作上运行vb.net中的线程 [ ^ ],

在启用禁用+多线程后控制事件未触发 [ ^ ]。



-SA
You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA


这篇关于交叉线不能在一个表格上发生两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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