Geeks With Blogs
Rohit Gupta Engaging talk on Microsoft Technologies ....My Resume
I needed to schedule a task to run every day at 9:00 p.m. in the night. I had an addition al requirement that the task be scheduled only if the FileSystemwatcher alerts us of new files being available for processing.

Thus the files could be recieved anytime during the day, but despite that the task should be schduled to run exactly at 9:00 p.m. in the night.

So I used the following code to schedule a task(using System.Threading.Timer and TimeSpan classes)

DateTime d = DateTime.Now;
timer = new Timer(new TimerCallback(Update), null, 
TimeSpan.FromMinutes(21 * 60 - (d.Hour * 60 + d.Minute)), 
TimeSpan.FromMilliseconds(-1));

Note I used TimeSpan.FromMillisecnods(-1) to disable periodic signalling Posted on Tuesday, November 18, 2008 12:31 PM | Back to top


Comments on this post: Schedule a task using C# code

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Rohit Gupta | Powered by: GeeksWithBlogs.net