I am working with a small experiment project with windows form application and I got a problem with while loop, after button click. After I click button2 the boolean b
should be changed to false and the loop should stop but it isn't.
namespace Spalvos
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Boolean b;
private void button1_Click(object sender, EventArgs e)
{
b = true;
while (b == true) {
Random rnd = new Random();
int r = rnd.Next(0, 254);
int n = rnd.Next(0, 254);
int d = rnd.Next(0, 254);
this.BackColor = Color.FromArgb(r, n, d);
Application.DoEvents();
System.Threading.Thread.Sleep(200);
}
}
private void button2_Click(object sender, EventArgs e)
{
b = false;
}
}
}