using System; using System.Windows.Forms; using System.Threading; namespace InvokeTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Thread th; private void button1_Click(object sender, EventArgs e) { if (th == null) { th = new Thread(() => { try { int st = 0; int.TryParse(textBox1.Text, out st); for (int i = st; ; i++) { this.Invoke((MethodInvoker)(() => { textBox1.Text = "" + i; })); //this.BeginInvoke((MethodInvoker)(() => { textBox1.Text = "" + i; })); } } catch (ThreadInterruptedException) { } }); th.Start(); button1.Text = "停止"; } else { th.Interrupt(); th = null; button1.Text = "開始"; } } } }