fork download
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Threading;
  4.  
  5. namespace InvokeTest
  6. {
  7. public partial class Form1 : Form
  8. {
  9. public Form1()
  10. {
  11. InitializeComponent();
  12. }
  13.  
  14. Thread th;
  15. private void button1_Click(object sender, EventArgs e)
  16. {
  17. if (th == null)
  18. {
  19. th = new Thread(() =>
  20. {
  21. try
  22. {
  23. int st = 0;
  24. int.TryParse(textBox1.Text, out st);
  25. for (int i = st; ; i++)
  26. {
  27. this.Invoke((MethodInvoker)(() => { textBox1.Text = "" + i; }));
  28. //this.BeginInvoke((MethodInvoker)(() => { textBox1.Text = "" + i; }));
  29. }
  30. }
  31. catch (ThreadInterruptedException) { }
  32. });
  33. th.Start();
  34. button1.Text = "停止";
  35. }
  36. else
  37. {
  38. th.Interrupt();
  39. th = null;
  40. button1.Text = "開始";
  41. }
  42. }
  43. }
  44. }
  45.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty