My.Application.Shutdown Event
Occurs when the application shuts down.
' Usage
Public Sub Me_Shutdown( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles Me.Shutdown
End Sub
' Declaration
Public Event Shutdown( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
)
Parameters
Remarks
An application raises the Shutdown event before it exits. This allows you to control how the application closes its resources. This event is part of the Visual Basic Application model. For more information, see Overview of the Visual Basic Application Model.
The code for the Shutdown event handler is stored in the ApplicationEvents.vb file, which is hidden by default.
To access the Code Editor window for application events
With a project selected in Solution Explorer, click Properties on the Project menu.
Click the Application tab.
Click the View Application Events button to open the Code Editor.
For more information, see How to: Handle Application Events (Visual Basic).
Tasks
The following table lists examples of tasks involving the My.Application.Shutdown event.
To |
See |
---|---|
Use the events provided by the Visual Basic Application model to run code |
|
Log a message when the application shuts down |
How to: Log Messages When the Application Starts or Shuts Down |
Example
This example logs messages when the application shuts down.
Private Sub MyApplication_Shutdown( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles Me.Shutdown
My.Application.Log.WriteEntry("Application Shut Down.")
End Sub
You must enter the code in the Code Editor window for application events. To access this window, follow the instructions from this topic's Remarks section. For more information, see How to: Log Messages When the Application Starts or Shuts Down.
Requirements
Namespace:Microsoft.VisualBasic.ApplicationServices
Class:WindowsFormsApplicationBase
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
Project type |
Available |
---|---|
Windows Application |
Yes |
Class Library |
No |
Console Application |
No |
Windows Control Library |
No |
Web Control Library |
No |
Windows Service |
No |
Web Site |
No |
Permissions
No permissions are required.
See Also
Tasks
How to: Log Messages When the Application Starts or Shuts Down
How to: Handle Application Events (Visual Basic)
Concepts
Overview of the Visual Basic Application Model