我需要帮助在visual basic(控制台应用程序)中创建一个计时器 [英] I need help creating a timer in visual basic(console application)
本文介绍了我需要帮助在visual basic(控制台应用程序)中创建一个计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个计时器,以便在60秒后,main sub中的变量将设置为true。如果有人可以提供帮助,那将非常感激。
I'd like to create a timer so that after 60 seconds, a variable from the main sub will be set to true. If anyone could help, that would be very much appreciated.
* fat dab *
*fat dab*
推荐答案
尝试使用这样的代码,适应您的需求
Try using code like this, adapt to your needs
Imports System
Imports System.Timers
Public Class Example
Private Shared aTimer As System.Timers.Timer
Public Shared Sub Main()
SetTimer()
Console.WriteLine(vbLf & "Press the Enter key to exit the application..." & vbLf)
Console.WriteLine("The application started at {0:HH:mm:ss.fff}", Date.Now)
Console.ReadLine()
aTimer.Stop()
aTimer.Dispose()
Console.WriteLine("Terminating the application...")
End Sub
Private Shared Sub SetTimer()
' Create a timer with a two second interval.
aTimer = New System.Timers.Timer(2000)
' Hook up the Elapsed event for the timer.
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.AutoReset = True
aTimer.Enabled = True
End Sub
Private Shared Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs)
Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}", e.SignalTime)
End Sub
End Class
这篇关于我需要帮助在visual basic(控制台应用程序)中创建一个计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文