Is there any way to capture application exit event in vb.net windows form system?

Viewed 6424

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.

2 Answers
Related