我使用线程但GUI冻结 [英] I using thread but GUI freeze

查看:122
本文介绍了我使用线程但GUI冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法:



I have a method:

private void CheckMsDevices() {
    string DevicesID;
    string IPAddress;
    int Port;
    int CommKey;

    Dt = new DataTable();
    StrSQL = "select DevicesID, IPAddress, Port, CommKey from MsDevices";
    if (cldb.sqlSelectReturnDt(StrSQL, Dt) == 1) {
        for (int i = 0; i < Dt.Rows.Count; i++) {
            DevicesID = Convert.ToString(Dt.Rows[i]["DevicesID"]);
            IPAddress = Convert.ToString(Dt.Rows[i]["IPAddress"]);
            Port = Convert.ToInt32(Dt.Rows[i]["Port"]);
            CommKey = Convert.ToInt32(Dt.Rows[i]["CommKey"]);

            Cursor = Cursors.WaitCursor;
            axCZKEM1.SetCommPassword(CommKey);
            bIsConnected = axCZKEM1.Connect_Net(IPAddress, Port);
            if (bIsConnected == true) {
                StrSQL = "update MsDevices set Status=1, EditBy='" + MasterForm.UserName + "', EditDate=GetDate() where DevicesID='" + DevicesID + "'";
                cldb.SqlExecuteQuery(StrSQL);

                axCZKEM1.RegEvent(1, 65535);
            } else {
                StrSQL = "update MsDevices set Status=0, EditBy='" + MasterForm.UserName + "', EditDate=GetDate() where DevicesID='" + DevicesID + "'";
                cldb.SqlExecuteQuery(StrSQL);
            }
        }

        BindData();
    }
}





该方法用于检查是否与指纹连接。





和我班级建设



which the method is used to check whether connected or not with finger print.


and my class construction

public FrmMsDevices() {
            InitializeComponent();

            Control.CheckForIllegalCrossThreadCalls = false;

            Thread.Sleep(120000);
            Thread t = new Thread(CheckMsDevices);
            t.IsBackground = true;
            t.Start();
        }







但是在运行时GUI冻结。

我该怎么办以及冻结怎么办?



谢谢。




But at run time GUI freeze.
What should I do and how that does not happen freeze?

Thank you.

推荐答案

嗯它将:

Well it will:
Thread.Sleep(120000);

会看到它,因为它让当前线程进入睡眠状态两分钟!如果您调用此代码,它将始终等待2分钟 它启动新线程...

will see to that as it puts the current thread to sleep for two minutes! If you call this code it will always wait 2 minutes before it starts the new thread...


这篇关于我使用线程但GUI冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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