代码如下:
private void ShowMsg(string msg) { if (this.InvokeRequired) { this.Invoke(new Action<string>(ShowMsg), msg); } else { this.txbLog.AppendText(msg); } } private void btnLive_Click(object sender, EventArgs e) { if (this.btnLive.Text == "Live") { islive = true; this.btnLive.Text = "Manual"; thread1 = new Thread(Live); thread1.Start(); } else { islive = false; this.btnLive.Text = "Live"; thread1.Abort(); } } private void Live() { while (islive) { string result="123"; this.ShowMsg(result); Thread.Sleep(500); } }