c#中的异步套接字编程,跨线程访问问题 [英] asynchronous socket programming in c#, cross thread access problem
问题描述
大家好,
我正在开发基于客户端/服务器的桌面应用程序。我使用异步套接字模式来连接客户端和服务器。我正在从客户端向服务器发送一些文本,在服务器上有一个接收回调函数正在接收数据。当我尝试在服务器显示表单上的文本框控件中插入接收的文本时。我得到以下异常。
跨线程操作无效:控制'txtMessage'从其创建的线程以外的线程访问。
我不知道如何在桌面文本框中显示收到的数据?
提前感谢您的时间。
您必须使用调度程序,如果您使用多线程来提高Windows窗体应用程序的性能,您必须确保以线程安全的方式调用控件。
参考:如何:对Windows窗体控件进行线程安全调用 [ ^ ]
- Amit
< blockquote>看看这里:如何解决跨线程操作无效 [ ^ ]
更多有用的链接:
代表教程 [ ^ ]
Control.Invoke Method(Delegate)/ a> [ ^ ]
Hi every one,
I am working on a client/Server based desktop application. I am using asynchronous socket mode to connect client and server. I am sending some text from client to Server and there on Server a receive call back function is receiving data. When i try to insert the received text in the Textbox control on Server Display form. I get the following exception.
"Cross-thread operation not valid: Control 'txtMessage' accessed from a thread other than the thread it was created on."
I have no idea how to display the received data in the desktop Text box?
thanks in advance for your time.
You will have to use a dispatcher, if you are using multithreading to improve the performance of your Windows Forms applications, you must make sure that you make calls to your controls in a thread-safe way.
Refer : How to: Make Thread-Safe Calls to Windows Forms Controls[^]
--Amit
Have a look here: How to solve "Cross thread operation not valid"[^]
More useful links:
Delegates Tutorial[^]
Control.Invoke Method (Delegate)/a>[^]
这篇关于c#中的异步套接字编程,跨线程访问问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!