关于 c#:使定时器经过事件hibernate | 珊瑚贝

Making the Timer Elapsed Event Sleep


我正在使用计时器经过事件进行自动数据库备份,计时器将每 5 秒检查一次,一旦当前时间等于 app.config 中给定的时间,就会发生数据库备份。我想让计时器在备份发生时不立即再次检查。谁能帮帮我。

  • 您指的是 System.Windows.Forms.Timer、System.Timers.Timer 还是 System.Threading.Timer?


once the current time equals to the time given in app.config the database backup will happen

这有一个不工作的诀窍。配置可以说 10:05:00,计时器在 10:04:58 和 10:05:03 结束。每 5 秒触发一次计时器是没有意义的。就开火一次。备份到期时。如果用户更改了到期时间,请停止并重新启动计时器以使用更改后的 TimeSpan。


如果使用 Sytem.Timers.Timer 对象,你会这样做

1
timer.Stop()

作为你过去事件的第一行,然后做备份,然后做

1
timer.Start()

在结束时重新开始活动。

如果使用 System.Threading.Timer 使用

1
timer.Change(Timeout.Infinite, Timeout.Infinite)

然后使用适当的值重新启动它。


备份运行时暂停计时器。

否则..(不确定您使用的是什么 DBS)为什么不使用 SQL Server 代理作业?


来源:https://www.codenong.com/5078332/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9988.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?