积极答复者
如何终止线程?

问题
答案
-
你好!参考下面的示例
System.Threading.Thread fThread; private void button1_Click(object sender, EventArgs e) { if (fThread == null) // 为 null 则启用新的线程 { fThread = new System.Threading.Thread(new System.Threading.ThreadStart(DoSth)); fThread.Start(); } else { fThread.Abort(); fThread = null; } } public void DoSth() { while (true) { this.BeginInvoke(new Action(delegate { this.Text = Guid.NewGuid().ToString(); })); System.Threading.Thread.Sleep(50); } }
知识改变命运,奋斗成就人生!- 已标记为答案 JSHZP 2011年9月14日 7:19
全部回复
-
你好!参考下面的示例
System.Threading.Thread fThread; private void button1_Click(object sender, EventArgs e) { if (fThread == null) // 为 null 则启用新的线程 { fThread = new System.Threading.Thread(new System.Threading.ThreadStart(DoSth)); fThread.Start(); } else { fThread.Abort(); fThread = null; } } public void DoSth() { while (true) { this.BeginInvoke(new Action(delegate { this.Text = Guid.NewGuid().ToString(); })); System.Threading.Thread.Sleep(50); } }
知识改变命运,奋斗成就人生!- 已标记为答案 JSHZP 2011年9月14日 7:19