在C#中,我曾经使用program.cs中的以下代码捕获应用程序退出事件。
static void OnProcessExit(object sender, EventArgs e)
{
string message = "The application was closed at :" + DateTime.Now.ToString() + ".";
}
VB.NET中的等价物是什么?
如果数据库连接在应用程序退出事件中有任何机会打开,我想关闭它。
答案 0 :(得分:3)
试试这个
AddHandler Application.ApplicationExit, AddressOf OnApplicationExit
Private Sub OnApplicationExit(ByVal sender As Object, ByVal e As EventArgs)
' When the application is exiting, write the application data to the
' user file and close it.
WriteFormDataToFile()
Try
' Ignore any errors that might occur while closing the file handle.
userData.Close()
Catch
End Try
End Sub
答案 1 :(得分:1)
双击MyProject
,然后点击Application Tab
,然后点击View Application Events
按钮。 Shutdown有一个事件 - 当应用程序关闭时会触发。