本文整理匯總了VB.NET中System.Windows.Application.Exit事件的典型用法代碼示例。如果您正苦於以下問題:VB.NET Application.Exit事件的具體用法?VB.NET Application.Exit怎麽用?VB.NET Application.Exit使用的例子?那麽, 這裏精選的事件代碼示例或許可以為您提供幫助。您也可以進一步了解該事件所在類System.Windows.Application
的用法示例。
在下文中一共展示了Application.Exit事件的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: WriteApplicationLogEntry
' 導入命名空間
Imports System.Collections
Imports System.Windows
Imports System.IO
Imports System.IO.IsolatedStorage
Namespace VisualBasic
Public Enum ApplicationExitCode
Success = 0
Failure = 1
CantWriteToApplicationLog = 2
CantPersistApplicationState = 3
End Enum
Partial Public Class App
Inherits Application
Private Sub App_Exit(ByVal sender As Object, ByVal e As ExitEventArgs)
Try
' Write entry to application log
If e.ApplicationExitCode = CInt(ApplicationExitCode.Success) Then
WriteApplicationLogEntry("Failure", e.ApplicationExitCode)
Else
WriteApplicationLogEntry("Success", e.ApplicationExitCode)
End If
Catch
' Update exit code to reflect failure to write to application log
e.ApplicationExitCode = CInt(ApplicationExitCode.CantWriteToApplicationLog)
End Try
' Persist application state
Try
PersistApplicationState()
Catch
' Update exit code to reflect failure to persist application state
e.ApplicationExitCode = CInt(ApplicationExitCode.CantPersistApplicationState)
End Try
End Sub
Private Sub WriteApplicationLogEntry(ByVal message As String, ByVal exitCode As Integer)
' Write log entry to file in isolated storage for the user
Dim store As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
Using stream As Stream = New IsolatedStorageFileStream("log.txt", FileMode.Append, FileAccess.Write, store)
Using writer As New StreamWriter(stream)
Dim entry As String = String.Format("{0}: {1} - {2}", message, exitCode, Date.Now)
writer.WriteLine(entry)
End Using
End Using
End Sub
Private Sub PersistApplicationState()
' Persist application state to file in isolated storage for the user
Dim store As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
Using stream As Stream = New IsolatedStorageFileStream("state.txt", FileMode.Create, store)
Using writer As New StreamWriter(stream)
For Each entry As DictionaryEntry In Me.Properties
writer.WriteLine(entry.Value)
Next entry
End Using
End Using
End Sub
End Class
End Namespace