如何在C#中重置计时器? [英] How to reset a timer in C#?

查看:359
本文介绍了如何在C#中重置计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道三个 Timer 类,分别是 System.Threading.Timer System.Timers.Timer System.Windows.Forms.Timer ,但是这些都没有。 Reset()函数会将当前经过的时间重置为0。

There are three Timer classes that I am aware of, System.Threading.Timer, System.Timers.Timer, and System.Windows.Forms.Timer, but none of these have a .Reset() function which would reset the current elapsed time to 0.

是否存在具有此功能的BCL类?有没有非骇客的方式? (我认为更改时间限制可能会重置它)。思考重新实现具有此功能的 Timer 类将有多困难,或者如何可靠地实现它

Is there a BCL class that has this functionality? Is there a non-hack way of doing it? (I thought perhaps changing the time limit on it might reset it) Thought on how hard it would be to reimplement a Timer class that had this functionality, or how to do it reliably with one of the BCL classes?

推荐答案

我总是这样做...

myTimer.Stop();
myTimer.Start();

...这是黑客吗? :)

... is that a hack? :)

关于Threading.Timer的每个注释,它是更改方法 ...

Per comment, on Threading.Timer, it's the Change method ...


dueTime类型:系统。 Int32 在构造计时器时,
在调用回调方法之前延迟的时间
指定了
,以
毫秒为单位。指定
Timeout.Infinite 以防止
计时器重新启动。指定零
(0)可立即重新启动计时器。

dueTime Type: System.Int32 The amount of time to delay before the invoking the callback method specified when the Timer was constructed, in milliseconds. Specify Timeout.Infinite to prevent the timer from restarting. Specify zero (0) to restart the timer immediately.

这篇关于如何在C#中重置计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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