Hi all,
I just found found a real annoying problem regarding catching when Windows is requesting a Shutdown or LogOff using SystemEvents.SessionEnding. My app succeed to catch the event when the form is minimized, but not when the form is opened and visible to user on screen, how come?
This is the code I´m using:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf SessionEnding
End Sub
Private Sub SessionEnding(ByVal sender As System.Object, ByVal e As Microsoft.Win32.SessionEndingEventArgs)
Select Case e.Reason
Case Microsoft.Win32.SessionEndReasons.Logoff
MsgBox("Logoff detected...", MsgBoxStyle.Information, "HandlerResult")
Case Microsoft.Win32.SessionEndReasons.SystemShutdown
MsgBox("SystemShutdown detected...", MsgBoxStyle.Information, "HandlerResult")
End Select
End Sub
Looking forward to your helpful answers
I just found found a real annoying problem regarding catching when Windows is requesting a Shutdown or LogOff using SystemEvents.SessionEnding. My app succeed to catch the event when the form is minimized, but not when the form is opened and visible to user on screen, how come?
This is the code I´m using:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf SessionEnding
End Sub
Private Sub SessionEnding(ByVal sender As System.Object, ByVal e As Microsoft.Win32.SessionEndingEventArgs)
Select Case e.Reason
Case Microsoft.Win32.SessionEndReasons.Logoff
MsgBox("Logoff detected...", MsgBoxStyle.Information, "HandlerResult")
Case Microsoft.Win32.SessionEndReasons.SystemShutdown
MsgBox("SystemShutdown detected...", MsgBoxStyle.Information, "HandlerResult")
End Select
End Sub
Looking forward to your helpful answers