WPF .NET触发一个事件每分钟最好的方法 [英] WPF .NET Best way to trigger an event every minute
问题描述
我有一个应用程序,需要检查数据库表中的每一分钟。此表按一天的时间索引,因此应用程序需要运行该检查的每一分钟。
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,
西蒙
推荐答案
的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx">DispatchTimer就是你追求的是什么 - 只是设置所需的间隔,然后附加一个方法Tick事件 - 工程请客
The DispatchTimer 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触发一个事件每分钟最好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!