The timer is all you need. The infinite loop is rapidly resetting the timer, so nothing happens.
private void InitLoop(bool runLoop)
{
try
{
myTimer.Elapsed += myTimer_Elapsed;
myTimer.Interval = 2000;
myTimer.Enabled = true;
myTimer.Start();
}
catch (Exception f)
{
//handle the exception
}
}
typically you don't want an infinite loop without some kind of a thread.sleep() command, because it will also drive the CPU to 100% trying to run the loop as fast as possible.