.net 如何确定计时器是否正在运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/150575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 10:09:05  来源:igfitidea点击:

How to find out if a Timer is running?

.nettimer

提问by George Mauer

If I have an instance of a System.Timers.Timer that has a long interval - say 1 minute, how can I find out if it is started without waiting for the Tick?

如果我有一个 System.Timers.Timer 的实例,它有一个很长的间隔 - 比如说 1 分钟,我怎样才能知道它是否在不等待 Tick 的情况下启动?

回答by Ron Savage

System.Timer.Timer.Enabledshould work, when you call "Start" it sets Enabled to TRUE, "Stop" sets it to FALSE.

System.Timer.Timer.Enabled应该可以工作,当您调用“Start”时,它会将 Enabled 设置为 TRUE,“Stop”将其设置为 FALSE。

回答by Inisheer

if (timer1.Enabled)
{
   // Do Something
}

回答by Joe

If Timer.Enabled is true, your timer is running.

如果 Timer.Enabled 为 true,则您的计时器正在运行。

Calling Timer.Start sets Enabled to true.

调用 Timer.Start 将 Enabled 设置为 true。

Calling Timer.Stop sets Enabled to false.

调用 Timer.Stop 将 Enabled 设置为 false。

If Timer.AutoReset is true, then Enabled will automatically be set to false the first time the timer expires.

如果 Timer.AutoReset 为 true,则 Enabled 将在计时器第一次到期时自动设置为 false。

回答by Bob King

Use the timer's Enabledproperty.

使用计时器的Enabled属性。

回答by Johnno Nolan

You should check that timer is enabled

您应该检查计时器是否已启用