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();
        }
    }

相关文章:

  • 2021-08-12
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2021-07-21
  • 2021-05-26
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2021-05-06
  • 2021-11-25
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案