本文整理汇总了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