我们如何在 VB.Net 控制台应用程序中使用计时器控件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3820165/
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
How can we use timer control in VB.Net Console Application?
提问by Rajdeep
I am trying to use a Timer control in my console application.
我正在尝试在我的控制台应用程序中使用 Timer 控件。
Friend WithEvents XTIMER As System.Windows.Forms.Timer
I am setting all its properties. I have set the interval to 15000 ms. But even when I set the Enabled state of the timer control to be true, the tick event is not firing. Can any one help me out please?
我正在设置它的所有属性。我已将间隔设置为 15000 毫秒。但即使我将计时器控件的 Enabled 状态设置为 true,tick 事件也不会触发。任何人都可以帮我吗?
采纳答案by Mohamad Alhamoud
Use the Timer Class
使用定时器类
回答by dbasnett
Module Module1
Sub Main()
aTimer.AutoReset = True
aTimer.Interval = 2000 '2 seconds
AddHandler aTimer.Elapsed, AddressOf tick
aTimer.Start()
Console.ReadKey()
End Sub
Dim aTimer As New System.Timers.Timer
Private Sub tick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
Console.WriteLine("tick")
End Sub
End Module
回答by Tom Juergens
Use System.Timers.Timer instead. Here's a very good comparison of the timer classes.
回答by Alex Essilfie
Import the System.Windows.Forms
reference and use the Timer
class.
导入System.Windows.Forms
引用并使用Timer
类。