I have a simple problem with a code from a C# book. The code is suppose to change background color every time I click the button. The problem is it changes the color to green and instantly goes back to purple again. After clicking again, the situation and colors stay the same. I think there's a problem with Application.DeEvents() because it seems that after one iteration, parameters goes back to default. This is a book's fault obviously but I wanted to make it work, anyway. I found a question about the very same code but it was about for loop and it's not said why code can't work in the first place.
{
for (int c = 0; c < 254 && Visible; c++)
{
this.BackColor = Color.FromArgb(c, 255 - c, c);
Application.DoEvents();
System.Threading.Thread.Sleep(5);
}
}
}