I have to test a boolean every 250ms, max 2 seconds, and stop when it's true.
Tried this, but Thread.Sleep isn't a good solution for me because it's freezing my software, and waiting for even more won't change anything because the boolean won't change while it's frozen.
bool onLine = false;
Stopwatch chrono = new Stopwatch();
chrono.Start();
while (chrono.ElapsedMilliseconds < 2000)
{
if (!State().Equals(Online))
{
System.Threading.Thread.Sleep(250);
}
else
{
onLine = true;
operationCompleted();
break;
}
}
if (!onLine)
{
MessageBox.Show("Error");
}
I don't know how to make the tests in an event raised by a timer if someone has a correct implementation?