My.Application.Shutdown 事件
更新:2007 年 11 月
發生在應用程式關閉的時候。
' 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 _
)
參數
備註
應用程式在結束之前會引發 Shutdown 事件。這可以讓您控制應用程式如何關閉它的資源。這個事件是 Visual Basic 應用程式模型的一部分。如需詳細資訊,請參閱 Visual Basic 應用程式模型概觀。
Shutdown 事件處理常式的程式碼儲存在 ApplicationEvents.vb 檔中,檔案預設為隱藏檔。
若要存取應用程式事件的程式碼編輯器視窗
在 [方案總管] 中選取了專案之後,請在 [專案] 功能表,按一下 [屬性]。
按一下 [應用程式] 索引標籤。
按一下 [檢視應用程式事件] 按鈕,開啟 [程式碼編輯器]。
如需詳細資訊,請參閱 HOW TO:處理應用程式事件 (Visual Basic)。
工作
下表列出包含 My.Application.Shutdown 事件的工作範例。
若要 |
請參閱 |
---|---|
請使用 Visual Basic 應用程式模型所提供的事件,執行程式碼 |
|
在應用程式關閉時記錄訊息 |
範例
這個範例會在應用程式關閉時記錄訊息。
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
您必須在應用程式事件的 [程式碼編輯器] 視窗中輸入程式碼。若要存取這個視窗,請依照此主題中註解章節的指示進行。如需詳細資訊,請參閱 HOW TO:在應用程式啟動或關閉時記錄訊息。
需求
命名空間:Microsoft.VisualBasic.ApplicationServices
類別︰WindowsFormsApplicationBase
組件 (Assembly):Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)
依專案類型的可用性
專案類型 |
是否可用 |
---|---|
Windows 應用程式 |
是 |
類別庫 |
否 |
主控台應用程式 |
否 |
Windows 控制項程式庫 |
否 |
Web 控制項程式庫 |
否 |
Windows 服務 |
否 |
網站 |
否 |
使用權限
不需要使用權限。
請參閱
工作
HOW TO:處理應用程式事件 (Visual Basic)