fork download
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Threading;
  4.  
  5. class MainForm : Form {
  6. TextBox textBox;
  7. Thread thread;
  8. volatile bool abortRequest = false;
  9. volatile bool activeBackground = false;
  10. void DoBackgroundWork() {
  11. activeBackground = true;
  12. while (!abortRequest) {
  13. Thread.Sleep(1000);
  14. this.BeginInvoke(new EventHandler((sender, e) => { textBox.AppendText("."); }),
  15. new object [] { this, EventArgs.Empty });
  16. }
  17. this.Invoke(new EventHandler((sender, e) => {
  18. textBox.AppendText(Environment.NewLine + "UI同期が必要な終了処理");
  19. activeBackground = false;
  20. this.Close();
  21. }), new object [] { this, EventArgs.Empty });
  22. }
  23. public MainForm() {
  24. thread = new Thread(DoBackgroundWork);
  25. textBox = new TextBox() { Multiline= true, Dock = DockStyle.Fill };
  26. this.Controls.Add(textBox);
  27. this.Load += (sender, e) => { thread.Start(); };
  28. this.Closing += (sender, e) => {
  29. if (activeBackground) {
  30. abortRequest = true;
  31. e.Cancel = true;
  32. }
  33. };
  34. }
  35. }
  36. class Program {
  37. static void Main() {
  38. Application.Run(new MainForm());
  39. }
  40. }
  41.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(2,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(6,3): error CS0246: The type or namespace name `TextBox' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty