当我在应用程序上未工作15分钟时,请关闭我的应用程序。 Vb.net

时间:2018-10-04 10:16:49

标签: vb.net timer exit

我正在使用Visual Studio2015。使用VB.net创建应用程序 我有必需的自动退出应用程序。当我在应用程序上无法工作15分钟时,请关闭我的应用程序。 谢谢

1 个答案:

答案 0 :(得分:1)

您可以这样做

Public Class Form1
Dim app As Application

Private Sub MainWindow_Loaded(sender As Object, e As EventArgs) Handles Me.Load

    Dim aTimer As System.Timers.Timer
    aTimer = New System.Timers.Timer()
    aTimer.Interval = 5000

    ' Hook up the Elapsed event for the timer.  
    AddHandler aTimer.Elapsed, AddressOf OnTimedEvent

    ' Start the timer
    aTimer.Enabled = True
End Sub

在引发事件中,您可以这样编写...

Private Sub OnTimedEvent(source As Object, e As System.Timers.ElapsedEventArgs)

     'Environment.Exit(0) - closes without a problem

     'Application.Exit() - closes without a problem

     'closes without a problem.
     app.Exit()


    'Me.Close() - System.InvalidOperationException
 End Sub