gate_s

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

public partial class Form1 : Form
    {
       static public bool flag; 
        public Form1()
        {
            InitializeComponent();
        }

        static public void Monitor()
        { 
                string mystring = "hello!";
                for (int i = 0; i < mystring.Length; i++)
                {
                    if (flag == false)  //马上结束
                        break;
                    else
                        MessageBox.Show(mystring[i].ToString());
                }
        }
        private void 开始_Click(object sender, EventArgs e)
        {
            timer1_Tick(null,null); //立即开始
            timer1.Enabled = true;
            flag = true;
        }

        private void 结束_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            flag = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Thread threadMonitor = (new Thread(new ThreadStart(Monitor)));
            threadMonitor.Start();
        }
    }

posted on 2014-02-14 09:31  gate_s  阅读(545)  评论(0编辑  收藏  举报