I use the following code to wait for the 'Ready' flag to be set from a message handler in my application:
void WaitSomeObjectToBeReady()
{
int WaitTime = 100;
int WaitInterval = 100;
Application.DoEvents();
int t = 0;
for (; t < WaitTime; ++t)
{
if (SomeObject.Ready)
{
break;
}
Thread.Sleep(WaitInterval);
Application.DoEvents();
}
if (t == WaitTime)
{
Assert.Fail("Time out waiting {0}.", flag_name);
}
}
Is there a better way ( without Thread.Sleep )

Question on application message loop