C#计时器触发每X秒,但保持同步与实时(即无漂移) [英] C# timer that fires every X seconds, but stays in synch with real time (i.e. with no drift)

查看:142
本文介绍了C#计时器触发每X秒,但保持同步与实时(即无漂移)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个.NET定时器在C#中,可以确保没有在事件之间没有漂移可用?也就是说,如果你设置定时熄灭每X秒,在操作它的天后不会随波逐流,即保证了X秒事件的方法数在一天保持同步与它应该是什么?

Is there a .NET Timer available in C# that can ensure there is no "drift" in between events? That is, if you set the timer to go off every X seconds, that after days of operating it won't drift, i.e. to ensure that approach number of X seconds events in a day remains in synch with what it should be?

如果没有,有没有将包装在C#中的计时器功能众所周知code的例子来做到这一点?

If not, is there a well known code example that would wrap a Timer function in C# to do this?

推荐答案

抱歉,只给你 quartz.net链接,但是这是一个完全合格的,企业的,经过测试,...库......你不需要重新发明轮子:)

sorry for only giving you a link to quartz.net, but this is a fully qualified, enterprise, tested, ... library ... you don't need to reinvent the wheel :)

如果你担心的开销,你有什么定义开销?是它的文件大小(二进制约为0,5mb)或逻辑的开销。 以及用于逻辑部分:我认为,实现他们的 IJob -interface做了很好的工作,迫使消费者更好的code。我不是一个内联方法的大朋友(只是举个例子,你可能会解雇他们的计时器经过指针) - 班会给你更多的可能性,并再次,强制更好的空中接力,域设计,..

if you worry about overhead, what is your definition for overhead? is it the file-size (binaries are about 0,5mb) or the overhead in the logic. well for the logic-part: i think that implementing their IJob-interface does a good job to force better code of the consumer. i'm not that big friend of inline-methods (just as an example, as you might fire their pointers on timer elapse) - classes would give you much more possibilities, and once again, force better oop, domain-design, ...

不过:做 Console.WriteLine(...)与quartz.net将是矫枉过正...:)

but: doing Console.WriteLine(...) with quartz.net would be overkill ... :)

这篇关于C#计时器触发每X秒,但保持同步与实时(即无漂移)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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