Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a method:

C#
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
C#
public FrmMsDevices() {
            InitializeComponent();

            Control.CheckForIllegalCrossThreadCalls = false;

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



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

Thank you.
Posted

1 solution

Well it will:
C#
Thread.Sleep(120000);
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...
 
Share this answer
 
Comments
FX Andy Widjaja 30-May-14 3:40am    
yes i want this thread runs once every 2 minutes and continuous. but it made my GUI freeze.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900