关于System.Threading.Timer间隔 [英] about System.Threading.Timer interval

查看:104
本文介绍了关于System.Threading.Timer间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我在我的程序中设置一个计时器时,我使用了公共

计时器(TimerCallback,object,TimeSpan,TimeSpan)

构造函数。我希望定时器在挂载

时间后触发,所以我写了new Timer(new TimeCallback

(some_function),null,timeDiff,new TimeSpan)当我运行程序时,VS.NET弹出一个MsgBox,告诉我

计时器间隔必须小于2 ^ 32-2。实际上,

参数" timeDiff"可能会非常大(也许2或3美元b $ b年)。我怎么处理这个问题?


谢谢

小提琴

解决方案

violin wang< an ******* @ discussion.microsoft.com>写道:

当我在我的程序中设置一个计时器时,我使用了公共计时器(TimerCallback,object,TimeSpan,TimeSpan)
构造函数。我希望定时器在挂载
时间之后启动,所以我写了new Timer(new TimeCallback
(some_function),null,timeDiff,new TimeSpan)。当我
运行该程序,VS.NET弹出一个MsgBox,告诉我
定时器间隔必须小于2 ^ 32-2。实际上,
参数timeDiff可能会非常大(可能是2或3年)。我如何处理这个问题?




我建议有一个实际的计时器每天发射一次,仅为准确发射
真正的开火时间不到一天的时间。

这样,由于时钟变化,时间重新同步等原因,错过正确时间的可能性会减少。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件


" violin wang" <一个******* @ discussions.microsoft.com>在消息中写道

news:03 **************************** @ phx.gbl ... < blockquote class =post_quotes>当我在程序中设置一个计时器时,我使用了公共计时器(TimerCallback,object,TimeSpan,TimeSpan)
构造函数。我希望定时器在挂载
时间之后启动,所以我写了new Timer(new TimeCallback
(some_function),null,timeDiff,new TimeSpan)。当我
运行该程序,VS.NET弹出一个MsgBox,告诉我
定时器间隔必须小于2 ^ 32-2。实际上,
参数timeDiff可能会非常大(可能是2或3年)。我如何处理这个问题?




有一个不同的Timer()构造函数采用64位值。你可以用
代替TimeSpan。

http://msdn.microsoft.com/library/en...ctortopic2.asp


- - Alan


" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道

新闻:MP *********************** @ msnews.microsoft.co m ...

我建议有一个计时器,它实际上每天发射一次,只是为了准确而去。真正的开火时间不到一天的时间。
这样,由于时钟变化,时间重新同步等原因,错过正确时间的机会就会减少。



无论如何,计算机甚至可以启动和运行很长一段时间

而无需重新启动......每个Windows Update都会让你重新启动。 />

- Alan


hi
When I set up a timer in my program, I used public
Timer(TimerCallback, object, TimeSpan, TimeSpan)
constructor. I want the timer to fire after a mount of
time, so I wrote "new Timer(new TimeCallback
(some_function), null, timeDiff, new TimeSpan)".When I
ran the program, VS.NET popped a MsgBox that told me the
timer interval must be less than 2^32-2.Actually, the
argument "timeDiff" could be very large(maybe 2 or 3
years).How can I dealing with this problem?

thanks
violin

解决方案

violin wang <an*******@discussions.microsoft.com> wrote:

When I set up a timer in my program, I used public
Timer(TimerCallback, object, TimeSpan, TimeSpan)
constructor. I want the timer to fire after a mount of
time, so I wrote "new Timer(new TimeCallback
(some_function), null, timeDiff, new TimeSpan)".When I
ran the program, VS.NET popped a MsgBox that told me the
timer interval must be less than 2^32-2.Actually, the
argument "timeDiff" could be very large(maybe 2 or 3
years).How can I dealing with this problem?



I''d suggest having a timer which actually fired once a day, only going
for the "accurate" real firing time when it was less than a day away.
That way there''d be less chance of missing the correct time due to
clock changes, time resynchronization etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


"violin wang" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...

When I set up a timer in my program, I used public
Timer(TimerCallback, object, TimeSpan, TimeSpan)
constructor. I want the timer to fire after a mount of
time, so I wrote "new Timer(new TimeCallback
(some_function), null, timeDiff, new TimeSpan)".When I
ran the program, VS.NET popped a MsgBox that told me the
timer interval must be less than 2^32-2.Actually, the
argument "timeDiff" could be very large(maybe 2 or 3
years).How can I dealing with this problem?



There''s a different Timer() constructor that takes 64-bit values. You can
use that instead of TimeSpan.

http://msdn.microsoft.com/library/en...ctortopic2.asp

-- Alan


"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...

I''d suggest having a timer which actually fired once a day, only going
for the "accurate" real firing time when it was less than a day away.
That way there''d be less chance of missing the correct time due to
clock changes, time resynchronization etc.



It''s doubtful the computer will even be up and running that long anyway
without needing to be rebooted... Every Windows Update makes you reboot.

-- Alan


这篇关于关于System.Threading.Timer间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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