In C#, I used to capture the application exit event with the following code in program.cs.
static void OnProcessExit(object sender, EventArgs e)
{
string message = "The application was closed at :" + DateTime.Now.ToString() + ".";
}
What is the equivalent of this in VB.NET?
I want to close the database connection if it is open by any chance in the application exit event.
Try this
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
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With