I wanted to replace a counter based while loop with the timer based while loop in C#.
Example :
while(count < 100000)
{
//do something
}
Use a construct like this:
Timer r = new System.Timers.Timer(timeout_in_ms);
r.Elapsed += new ElapsedEventHandler(timer_Elapsed);
r.Enabled = true;
running = true;
while (running) {
// do stuff
}
r.Enabled = false;
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
running = false;
}
Be careful though to do this on the UI thread, as it will block input.