I had a requirement recently to run my little windows service every one minute or an interval thats configurable....
And Timers was straight forward solution for me...
Event on which you need to write your code is OnElapsedTime.
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
streamWriter = new StreamWriter(new FileStream(
"C:\\WindowsServiceLogger.txt", System.IO.FileMode.Append));
this.streamWriter.WriteLine(" My Service got invoked again at " +
DateTime.Now.ToString());
this.streamWriter.Flush();
this.streamWriter.Close();
Start();
}
My task for the service is written in Start() method so i can call it directly OnStart and OnElapsedTime
Please remember to enable your timer OnStart and disable OnStop.
Seems all simple and easy....and it is :)
Happy Coding
Monday, September 10, 2007
Subscribe to:
Post Comments (Atom)
this is gr8........but Samuel if i want to have the timer properties configurable, wer wil i put that???
ReplyDelete