C# 单步执行可以成功,直接运行却不能成功

# # 程序从timer2中执行到if (str1.Equals(""))

# {

# timer2.Enabled = false;

# textBox3.Text = "从联网状态变为断网,跳回到短间隔状态;";

# timer1.Enabled = true;

# timer1.Interval = 2000;

# }

# # 这段代码后,跳到timer1中,然后执行if条件成立时的代码,但就这段代码运行时会死机!

                private void timer1_Tick(object sender, EventArgs e)
        {
            TestNet testlink = new TestNet();
            string str1 = testlink.GetHostNameByIp("www.baidu.com");
            //Thread.Sleep(1000);
            if (str1.Equals(""))
            {
                timer1.Enabled = false;
                try
                {
                    this.webBrowser1 = new WebBrowser();
                    webBrowser1.ScriptErrorsSuppressed = true;
                    webBrowser1.Navigate("192.168.1.3");
                    //Thread.Sleep(1000); 
                    while (webBrowser1.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                    {
                        //textBox3.Text = "加载页面中。。。";
                        System.Windows.Forms.Application.DoEvents();
                    }
                    HtmlElement btnSubmit = webBrowser1.Document.All["submit"];
                    HtmlElement tbUserid = webBrowser1.Document.All["username"];
                    HtmlElement tbPasswd = webBrowser1.Document.All["password"];
                    while (tbUserid == null || tbPasswd == null || btnSubmit == null)
                    {
                        btnSubmit = webBrowser1.Document.All["submit"];
                        tbUserid = webBrowser1.Document.All["username"];
                        tbPasswd = webBrowser1.Document.All["password"];
                    }
                    tbUserid.SetAttribute("value", _uname);
                    tbPasswd.SetAttribute("value", _pword);
                    btnSubmit.InvokeMember("click");
                    //MessageBox.Show("OK");
                    textBox3.Text = "没联网,在短间隔联网;";
                }
                catch (Exception ex)
                {
                    //webBrowser1.Navigate("192.168.1.3");
                    MessageBox.Show("重复没能访问到");
                }
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
                textBox3.Text = "连上网了,变成长间隔联网;";
                timer2.Enabled = true;
                timer2.Interval = 5000;

            }
        }

                private void timer2_Tick(object sender, EventArgs e)
        {
            TestNet testlink = new TestNet();
            string str1 = testlink.GetHostNameByIp("www.baidu.com");
            if (str1.Equals(""))
            {
                timer2.Enabled = false;
                textBox3.Text = "从联网状态变为断网,跳回到短间隔状态;";
                timer1.Enabled = true;
                timer1.Interval = 2000;
            }
            else
            {
                timer2.Enabled = false;
                textBox3.Text = "一直在联网状态;";
                timer2.Enabled = true;
                timer2.Interval = 5000;
            }
        }

webBrowser1.ReadyState
这个判断未必正确

while (tbUserid == null || tbPasswd == null || btnSubmit == null)
{
这里也加上doevents
}