GitHub: [https://github.com/CarterWu-M/C-WinForms_sync-async]
This example code uses a text box and a button to observe a timer, setting a value in the text box every second. It also includes Thread.Sleep() and Task.Delay() for observations during the delay periods.

---
### Thread.Sleep()
---
```C#=
namespace sync_async
{
public partial class Form1 : Form
{
private System.Windows.Forms.Timer _timer;
private uint _elapsedSec = 0;
public Form1()
{
InitializeComponent();
this._timer = new System.Windows.Forms.Timer();
this._timer.Interval = 1000;
this._timer.Tick += Timer_tick;
}
private void Timer_tick(object sender, EventArgs e)
{
this._elapsedSec++;
TimeSpan timeSpan = TimeSpan.FromSeconds(this._elapsedSec);
txt1.Text = timeSpan.ToString(@"ss");
txt1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
txt1.Text = "Waiting for 5 seconds...";
txt1.Refresh();
this._elapsedSec = 0;
this._timer.Start();
//sync method, blocking UI
Thread.Sleep(5000);
this._timer.Stop();
txt1.Text = "Wait completed!";
txt1.Refresh();
}
}
}
```

=> UI is blocked for 5 seconds

You will find that the string only displays 'Waiting for 5 seconds...' and 'Wait completed!' You won't see the timer value '00', '01', '02'...for each second.
Because Thread.sleep() is a synchronous method, it will block the UI, preventing you from seeing any timer values on the screen.

---
### Task.Delay()
---
```C#=
private void button1_Click(object sender, EventArgs e)
{
txt1.Text = "Waiting for 5 seconds...";
txt1.Refresh();
this._elapsedSec = 0;
this._timer.Start();
//async method, non-blocking UI
Task.Delay(5000);
this._timer.Stop();
txt1.Text = "Wait completed!";
txt1.Refresh();
}
```

=> change immediately

you will see the string changed from 'Waiting for 5 seconds...' to 'Wait completed!' after a short delay.
Because Task.Delay() is an asynchronous method, it won't blok the UI thread, allowing the code to continue to the next line.

---
### Await Task.Delay()
---
```C#=
private async void button1_Click(object sender, EventArgs e)
{
txt1.Text = "Waiting for 5 seconds...";
txt1.Refresh();
this._elapsedSec = 0;
this._timer.Start();
//async method, non-blocking UI
await Task.Delay(5000);
this._timer.Stop();
txt1.Text = "Wait completed!";
txt1.Refresh();
}
```






Now you can see the timer value in the text box each second because 'await' will wait for Task.Delay() to complete before moving to the next line of code. Since Task.Delay() is an asynchronous method, it won't block the UI thread, allowing the timer to update the value in the text box.
When you use the 'await' syntax, remember to add the 'async' keyword before the function name.
