winform难题.高手进

 private bool IsRun;
        private void stop_Click(object sender, EventArgs e)
        {
            IsRun = false;
            StreamWriter sw = File.AppendText(@"d:\myserver.txt");
            sw.WriteLine(string.Format("停止:启动时间{0}", DateTime.Now));
            sw.Close();
        }

        private void begin_Click(object sender, EventArgs e)
        {
            IsRun = true;
            while (IsRun)
            {
                try
                {
                    StreamWriter sw = File.AppendText(@"d:\myserver.txt");
                    sw.WriteLine(string.Format("启动:启动时间{0}", DateTime.Now));
                    sw.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                System.Threading.Thread.Sleep(10000);
            }
        }
    }

当按下按钮beigin后。。为什么stop按钮无法被按下。。好像假死的状态?????????????

神不在的星期二
浏览 329回答 2
2回答

呼唤远方

System.Threading.Thread.Sleep(10000); 不是在这停了吗,你要开另外一个线程去做 begin_Click的事。
打开App,查看更多内容
随时随地看视频慕课网APP