WPF .NET 每分钟触发一个事件的最佳方式 [英] WPF .NET Best way to trigger an event every minute

查看:19
本文介绍了WPF .NET 每分钟触发一个事件的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序需要每分钟检查一次数据库表.该表按一天中的时间编制索引,因此应用需要每分钟运行一次此检查.

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 每分钟触发一个事件的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆