Windows窗体GUI冻结使用插座时 [英] Windows Forms GUI Freezing while Using Socket
问题描述
目前,当我尝试以显示我从套接字读取数据我的GUI结冰。这不是冻结当我显示一个或两个消息,只有当我收到很多邮件(2-3每秒)。我使用的异步接口(非阻塞)。我想这是关系到我如何显示数据的GUI。代码:
Currently my GUI is Freezing when I try to display data I read from my socket. It's not freezing when i display one, or two messages, only when I receive many messages(2-3 per sec). I am using async socket(non blocking). I guess it's related to how I display the data to the gui. Code:
public class Globals
{
public static MainDialog myDialog;
}
public partial class MainDialog : Form
{
public MainDialog()
{
InitializeComponent();
Globals.myDialog = this;
}
public void sendText(string text)
{
logBox.AppendText(text);
logBox.AppendText("\n");
}
}
然后,我只是叫Globals.myDialog.sendText(。从我的网络类)。正如我所说的它工作正常,但不是当我立刻收到许多邮件。
Then I simply call Globals.myDialog.sendText(..) from my network class. As I said it works fine, but not when I receive many messages at once.
人有一个想法?
推荐答案
还记得打电话的更新从其他线程GUI控制时,检查InvokeRequired。
Also remember to check for InvokeRequired when calling updates to gui controls from other threads.
这篇关于Windows窗体GUI冻结使用插座时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!