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
Showing posts with label windows service. Show all posts
Showing posts with label windows service. Show all posts
Monday, September 10, 2007
Subscribe to:
Posts (Atom)