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 = "開始";
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uV2luZG93cy5Gb3JtczsKdXNpbmcgU3lzdGVtLlRocmVhZGluZzsKCm5hbWVzcGFjZSBJbnZva2VUZXN0CnsKICAgIHB1YmxpYyBwYXJ0aWFsIGNsYXNzIEZvcm0xIDogRm9ybQogICAgewogICAgICAgIHB1YmxpYyBGb3JtMSgpCiAgICAgICAgewogICAgICAgICAgICBJbml0aWFsaXplQ29tcG9uZW50KCk7CiAgICAgICAgfQoKICAgICAgICBUaHJlYWQgdGg7CiAgICAgICAgcHJpdmF0ZSB2b2lkIGJ1dHRvbjFfQ2xpY2sob2JqZWN0IHNlbmRlciwgRXZlbnRBcmdzIGUpCiAgICAgICAgewogICAgICAgICAgICBpZiAodGggPT0gbnVsbCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdGggPSBuZXcgVGhyZWFkKCgpID0+CiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgdHJ5CiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBpbnQgc3QgPSAwOwogICAgICAgICAgICAgICAgICAgICAgICBpbnQuVHJ5UGFyc2UodGV4dEJveDEuVGV4dCwgb3V0IHN0KTsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgaSA9IHN0OyA7IGkrKykKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhpcy5JbnZva2UoKE1ldGhvZEludm9rZXIpKCgpID0+IHsgdGV4dEJveDEuVGV4dCA9ICIiICsgaTsgfSkpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy90aGlzLkJlZ2luSW52b2tlKChNZXRob2RJbnZva2VyKSgoKSA9PiB7IHRleHRCb3gxLlRleHQgPSAiIiArIGk7IH0pKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBjYXRjaCAoVGhyZWFkSW50ZXJydXB0ZWRFeGNlcHRpb24pIHsgfQogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICB0aC5TdGFydCgpOwogICAgICAgICAgICAgICAgYnV0dG9uMS5UZXh0ID0gIuWBnOatoiI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB0aC5JbnRlcnJ1cHQoKTsKICAgICAgICAgICAgICAgIHRoID0gbnVsbDsKICAgICAgICAgICAgICAgIGJ1dHRvbjEuVGV4dCA9ICLplovlp4siOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9Cg==