Hi Folks
I'm a bit new to C# and I'm interested in creating a timer that continually loops every 10 seconds until a condition is true. When the condition is true I want to stop the Timer, perform an action and then restart the timer again. I've got this far:
using System;
using System.IO;
using System.Threading;
using System.Timers;
public class Timer
{
public static void Main()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimer);
aTimer.Interval = 1000;
aTimer.Enabled = true;
Console.WriteLine("Press \'q\' to quit the timer"
while(Console.Read()!='q');
}
public static void OnTimer(Object source, ElapsedEventArgs e)
{
if (Condition is true )
{
aTimer.Enabled = false;
}
else
{
Continue ...
}
}
}
I can't seem to figure out how to stop the timer. Any ideas on what I need to be looking at?
Cheers,
Kenny.
I'm a bit new to C# and I'm interested in creating a timer that continually loops every 10 seconds until a condition is true. When the condition is true I want to stop the Timer, perform an action and then restart the timer again. I've got this far:
using System;
using System.IO;
using System.Threading;
using System.Timers;
public class Timer
{
public static void Main()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimer);
aTimer.Interval = 1000;
aTimer.Enabled = true;
Console.WriteLine("Press \'q\' to quit the timer"
while(Console.Read()!='q');
}
public static void OnTimer(Object source, ElapsedEventArgs e)
{
if (Condition is true )
{
aTimer.Enabled = false;
}
else
{
Continue ...
}
}
}
I can't seem to figure out how to stop the timer. Any ideas on what I need to be looking at?
Cheers,
Kenny.