Use an async method to create a delay using the built-in Task.Delay
method. This will cause execution to be paused and then resumed after the specified time without blocking the current thread.
async Task UseDelay() { await Task.Delay(1000); // wait for 1 second }
In your specific case
async void button1_Click(object sender, EventArgs e) { for (var i = 0; i < 10; i++) { textBox1.BackColor = Color.Red; await Task.Delay(100); textBox1.BackColor = Color.Yellow; await Task.Delay(100); } }