WPF .NET Best way to trigger an event every minute

前端 未结 3 1984
醉梦人生
醉梦人生 2020-12-09 02:40

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\'

3条回答
  •  Happy的楠姐
    2020-12-09 02:59

    Not sure about WPF, but in WinForms, there's a Timer control for this. If there isn't one, one way is the following loop:

    • Check if we're past the last minute set
    • If not, sleep for a short time and check again
    • Do stuff
    • Check the current time
    • Save the minute
    • Sleep for 60000ms - current time(sec and ms part) - some value

提交回复
热议问题