我有一个应用程序需要每分钟检查一次数据库表.该表按一天中的时间编制索引,因此应用需要每分钟运行一次此检查.
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.
最好的方法是什么?我可以创建一个后台工作线程,但是如果我在每次检查后将它设置为休眠 60 秒,我最终会因为调用检查的开销而错过一分钟.
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.
我记得我检查然后检查的那一刻吗,每 15 秒说一次,如果分钟改变了,则执行检查.
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?
我使用的是 WPF、VS2008 和 VB.NET
I'm using WPF, VS2008 and VB.NET
TIA,
西蒙
推荐答案DispatcherTimer 就是您所追求的 - 只需设置您想要的间隔,然后将方法附加到 Tick 事件 - 效果很好.
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.
更多推荐
WPF .NET 每分钟触发一个事件的最佳方式
发布评论