I am writing a program that will perform an operation every 10 or 15 minutes. I want it to be running all the time, so I need something that is cheap on processing power. What I have read so far seems to suggest that I want to use a Timer. Here is a clip of the code I have so far.
class Program { private static Timer timer = new Timer(); static void Main(string[] args) { timer.Elapsed += new ElapsedEventHandler(DoSomething); while(true) { timer.Interval = TimerMilliseconds(); // The duration of the wait will differ each time timer.Enabled=true; } } } The problem here is that the while loop just keeps executing rapidly. How do I halt execution until the timer is elapsed. My program really doesn't need to be multi threaded. Is a Timer the right tool for this job?
Thank you in advance for any help!
UPDATE: Sorry for the confusion. I have implemented the DoSomething method. I just did not include it as I don't believe it is part of my issue.
DoSomething.