fork download
  1. using System;
  2. using System.Drawing;
  3. using System.Threading.Tasks;
  4. using System.Threading;
  5. using System.Windows.Forms;
  6.  
  7. namespace WindowsFormsApplication6
  8. {
  9. public partial class Form1 : Form
  10. {
  11. public Form1()
  12. {
  13. InitializeComponent();
  14. }
  15.  
  16. private async void button1_Click(object sender, EventArgs e)
  17. {
  18. this.button1.Enabled = false; // ボタンを無効にする
  19. this.label1.Text = "実行中";
  20. this.timer1.Start();
  21.  
  22. // 重い処理は別タスクで非同期実行
  23. await Task.Run(() =>
  24. {
  25. // ちょっと時間のかかる処理
  26. Thread.Sleep(10000);
  27. });
  28.  
  29. this.timer1.Stop();
  30.  
  31. this.label1.Text = string.Empty;
  32. this.label1.BackColor = SystemColors.Control; // ラベルの背景色を元に戻す
  33. this.button1.Enabled = true; // ボタンを有効に戻す
  34. }
  35.  
  36. private void timer1_Tick(object sender, EventArgs e)
  37. {
  38. // ラベルの背景色を切り替える
  39. this.label1.BackColor = this.label1.BackColor == SystemColors.Control ? Color.Red : SystemColors.Control;
  40. }
  41. }
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(5,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(9,34): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty