Reputation: 36
I want to frequently check the server for new data. means i want to fire the select command for every 20 minutes to check database table. i am using windows form application 2008.
Upvotes: 0
Views: 1217
Reputation: 12314
If the app does nothing else I recommend scheduling it. Scheduling the app frees you from a whole set of problems ranging from not having to implement Service-behaviour to avoiding instability due to not freeing unmanaged resources over time. Apps running for a long time can encounter problems, crash, freeze, etc. The task scheduler has options to kill long running apps and similar, so it is a good friend for such tasks.
If the app modifies its GUI use System.Forms.Timer (drag out a timer GUI control to the form).
If the app runs in the background use either System.Threading.Timer or a dedicated System.Threading.Thread with a wait loop containing System.Threading.Thread.Sleep.
If your app runs from ASP.Net then rumor has it Quartz is the way to go. Personally I'd recommend you don't run schedules from ASP.Net and instead take a good look at your architecture.
Upvotes: 1
Reputation: 15881
Quartz.NET is a very good library. I'm using it in my windows services. I suggest you should use cron trigger.
http://quartznet.sourceforge.net/
Upvotes: 0
Reputation: 1038780
You could use a Timer. And the corresponding documentation on MSDN:
var timer = new Timer(TimeSpan.FromMinutes(20).TotalMilliseconds);
timer.Elapsed += (sender, e) =>
{
// TODO: send a query to the database
};
timer.Start();
In Windows Forms you could also use the System.Windows.Forms.Timer class.
Upvotes: 1