应用程序在远程连接时冻结,Windows睡眠唤醒 [英] Application freezes on remote connection and windows sleep wakeup

查看:68
本文介绍了应用程序在远程连接时冻结,Windows睡眠唤醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过关于应用程序冻结的许多类似帖子,但没有解决我的问题.一切都在try catch块和backgroundworker中 但应用程序仍会冻结Internet连接是否处于活动状态.我调试了代码,发现导致以下代码.每次我启动应用程序时,都会在随机的时间间隔内发生这种情况.有时效果很好,但是当我睡在窗户上时 然后唤醒它,使应用程序变得繁忙.当我删除以下代码时,它可以正常工作,但我不知道此代码中的问题在哪里.

I have seen many similar posts regarding application freezing but did not solve my problem. Everything is in try catch block and in backgroundworker but still application freezes either the internet connection is alive or not. I have debugged the code and found causing the below code. This happens in random time spans each time I start the application. Sometimes it works fine but when I sleep the windows and then wakeup it the application gets busy. When I remove the following code it works fine but I don't know where is the problem in this code.

private void backgroundWorkercheckonline_DoWork(object sender, DoWorkEventArgs e)
    {
        string selectremotevalue = "SELECT InstallationKey, Status FROM  SMSClientTable";
        Liscenseform formcallliscence = new Liscenseform();
        string status = null;

        for (; ; )
        {

            if (backgroundWorkercheckonline.CancellationPending)
            {   e.Cancel = true;

                break;

            }

            #region




            MySqlConnection remotecon = new MySqlConnection(strsitecon);
            MySqlConnection remotecon1 = new MySqlConnection(strsitecon);

            try
            {
                remotecon.Open(); //open the connection
            }
            catch(Exception ex) 
            {
                MessageBox.Show("not connected to remote site");

                if (offlinestatus == "inactive")
                {
                    Messagebox formcall = new Messagebox();
                    formcall.ShowDialog();

                    Environment.Exit(0);
                }




                Thread.Sleep(1000 * 2 * 60); continue;
            }

            try
            {
                MySqlCommand selectvalue = new MySqlCommand(selectremotevalue, remotecon);
                MySqlDataReader remotereader = selectvalue.ExecuteReader();


                while (remotereader.Read())
                {

                   // MessageBox.Show(remotereader.GetString(0) + "|" + remotereader.GetString(1));
                    if (remotereader.GetString(0) == installationkey)
                    {
                        status = remotereader.GetString(1);

                        break;
                    }


                }
                remotereader.Close();
                remotecon.Close();


            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to read or connect");

            }



            if (status != null)
            {

                #region
                if (status == "Inactive" || status == "inactive")

                {


                    try
                    {
                        this.bwsttsrpi = new BinaryWriter(new FileStream("sttsrpi.ocx", FileMode.Create));

                        this.bwsttsrpi.Write("inactive");

                        bwsttsrpi.Close();
                    }
                    catch { }


                    Messagebox formcall = new Messagebox();
                    formcall.ShowDialog();


                    MessageBox.Show("SMS and Email Marketing Software has been registered with fake serial. The environment will now try to close.", "Fake Serial Notification");
                    Environment.Exit(0);


                }
                if (status == "active")
                {
                    if (offlinestatus == "inactive")
                    {
                        try
                        {
                            this.bwsttsrpi = new BinaryWriter(new FileStream("sttsrpi.ocx", FileMode.Create));

                            this.bwsttsrpi.Write("active");

                            bwsttsrpi.Close();
                        }
                        catch { }



                    }

                    Thread.Sleep(1000 * 2 * 60); continue;

                }
                #endregion
            }




            else
            {
                try
                {
                    remotecon.Open(); //open the connection
                }
                catch (Exception ex)
                {
                }


                try
                {


                    String insrtablestr = "INSERT INTO SMSClientTable VALUES(@Name, @Email, @Phone, @Price, @InstallationKey, @SerialKey, @Status, @DateTime)";
                    MySqlCommand insertvalue = new MySqlCommand(insrtablestr, remotecon);
                    insertvalue.Prepare();

                    //we will bound a value to the placeholder
                    insertvalue.Parameters.AddWithValue("@Name", name);
                    insertvalue.Parameters.AddWithValue("@Email", email);
                    insertvalue.Parameters.AddWithValue("@Phone", Phone);
                    insertvalue.Parameters.AddWithValue("@Price", price);

                    insertvalue.Parameters.AddWithValue("@InstallationKey", installationkey);
                    insertvalue.Parameters.AddWithValue("@SerialKey", serialkey);
                    insertvalue.Parameters.AddWithValue("@Status", "active");
                    insertvalue.Parameters.AddWithValue("@DateTime", datetimecheck);


                    insertvalue.ExecuteNonQuery(); //execute the mysql command

                }
                catch (Exception ex)
                {


                }



            }

            #endregion


        }
        Environment.Exit(0);


    }

推荐答案

您好

Hi imran kanjoo

<身体>


这篇关于应用程序在远程连接时冻结,Windows睡眠唤醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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