可靠的替代定时器在.NET框架? [英] Reliable alternative to Timer in .NET framework?

查看:156
本文介绍了可靠的替代定时器在.NET框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有relialbe替代在.net Timer类?
我们有与System.Timers.Timer的和System.Threading.Timer,如问题,他们开始immidietly,或有时长一段时间不活动(49天以后)后火扑灭。
我已经看到了,似乎有很多问题,他们喜欢这里:<一href="http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/dbc398a9-74c0-422d-89ba-4e9f2499a6a3" rel="nofollow">http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/dbc398a9-74c0-422d-89ba-4e9f2499a6a3
我们不能用形式定时器。
我们正在考虑暂停的时间,而不是定时器一定期限内螺纹...

Is there relialbe alternative to Timer class in .Net?
We are having issues with System.Timers.Timer and System.Threading.Timer, e.g., they start immidietly, or sometimes fire out after long period of inactivity (after 49 days).
I've seen that there seems to be a lot of issues with them like here: http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/dbc398a9-74c0-422d-89ba-4e9f2499a6a3
We can not use Forms timer.
We are thinking to pause the thread for certain period of time instead of the timer...

推荐答案

这文章介绍.NET Framework中的计时器类之间的区别。

This article describes the difference between the timer classes in the .Net framework.

但也许另一种方法可以帮助:

But maybe another approach can help:

如果有需要等待这么长的时间它会更好地计算出的DateTime 当你喜欢的东西开始。事后的任务唤醒每秒(或需要任何精确度)和当前的时间与所需的时间进行比较。如果当前时间等于或大于刚开始你的工作。否则进入睡眠状态(直到下一秒钟,小时,毫秒,等等)。顺便说一句,这就是方式在Microsoft任务计划程序是如何工作的。

If have have to wait for such a long time it would be better to calculate the DateTime when you like something to start. Afterwards your task wakes up every second (or whatever accuracy is needed) and compares the current time with the desired time. If the current time is equal or greater just start your job. Otherwise go to sleep (till the next second, hour, millisecond, whatever). By the way, that's the way how the Microsoft Task Scheduler works.

这篇关于可靠的替代定时器在.NET框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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