Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF .NET Best way to trigger an event every minute

Tags:

.net

wpf

timer

I have an app that needs to check a database table every minute. The table is indexed by the time of day and so the app needs to run this check every minute.

What's the best of way of doing this? I can create a background worker thread but if I set it to sleep for 60 secs after each check I will eventually miss a minute because of the overhead of calling the check.

Do I remember the minute I checked and then check, every 15 secs say and if the minute has changed performed the check then.

Or is there some other approach I should use?

I'm using WPF, VS2008 and VB.NET

TIA,

Simon

like image 346
Simon Temlett Avatar asked Jan 26 '09 10:01

Simon Temlett


1 Answers

The DispatcherTimer is what you're after - just set the interval you want, and then attach a method to the Tick event - works a treat.

like image 183
MrTelly Avatar answered Sep 21 '22 11:09

MrTelly