我正在为特别繁忙的特定用户组构建一个简单的应用程序。 应用程序访问许可证;这是唯一的许可证。如果运行该应用程序的其中一个人忘记打开该应用程序,其他人将无法访问该资源。 我正在考虑使用计时器为应用程序设置超时,以便特定人员尚未完成与许可证的交互,应用程序将正确关闭以便释放许可证。 该应用程序是 vb.net 中的 Windows 窗体。如何将计时器设置为 15 分钟,并在计时器到期时执行关闭操作,或者在操作员在时限内完成工作时关闭计时器? 所有有关如何操作的示例都值得赞赏。
Imports System.Timers
Public Class Form1
Dim Timer As New Timer
Public LastAtivity As DateTime = Now
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer.Interval = 60000 'in milisecons = 1 minute
AddHandler Timer.Elapsed, New ElapsedEventHandler(AddressOf TimerElapsed)
AddHandler Application.Idle, AddressOf Application_Idle
Timer.Start()
End Sub
Private Sub Application_Idle(ByVal sender As Object, ByVal e As EventArgs)
LastAtivity = Now
Label1.Text = LastAtivity 'Whit this you can see the last user ativiti, you can remove this line.
End Sub
Public Sub TimerElapsed(sender As Object, e As ElapsedEventArgs)
If DateDiff(DateInterval.Minute, LastAtivity, Now) >= 15 Then End 'force the end of the application
End Sub
End Class