Jai
Jai

Reputation: 289

Best way to handle Timers?

I wanted to create something similar to the way anti-virus programs sit in the Tray and can re-do an event (e.g. a scan) on an interval. I have a program that exports data from our SQL server and the user sets up a queue of what they wanted exported.

I was thinking about using System.Windows.NotifyIcon http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx

and System.Timer http://msdn.microsoft.com/en-us/library/system.timers.timer%28v=vs.71%29.aspx

Let's say the user has it set to repeat every X hours or "Every Day" or "Every Wednesday at 5:00". Should I just create a tray icon and

this.Hide();

and setup a timer that ticks and compares the time when the timer was started against whatever criteria the user set? Or, is this an inefficient and memory wasting way to do it? Is there any way to "schedule" an event to fire at a certain time and handle it that way?

Upvotes: 2

Views: 221

Answers (1)

Albin Sunnanbo
Albin Sunnanbo

Reputation: 47038

You can use Windows scheduled tasks.

There is a library called Task Scheduler Managed Wrapper that can be used to set up tasks from c#.

Upvotes: 4

Related Questions