jazduck
asked on
Windows wont Shutdown when running my App
I have a slight problem - Windows wont shut down when its running my app. The code which affects it is below, the only problem is the same line of code is what stops my app closing when the [X] is clicked, so i can place it in the systemtray. Any info as to why this happens, or a workaround would be really helpful.
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.Canc elEventArg s) Handles MyBase.Closing
e.Cancel = True '<---- Culprit (Wont Allow Windows to Shutdown)
HideToSysTray()
End Sub
As an afterthought could probably set e.Cancel = False, if it's possible to detect when windows wants to shutdown.
Jaz
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.Canc
e.Cancel = True '<---- Culprit (Wont Allow Windows to Shutdown)
HideToSysTray()
End Sub
As an afterthought could probably set e.Cancel = False, if it's possible to detect when windows wants to shutdown.
Jaz
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
For any interested the code to detect a shutdown, and thus decide whether or not to close the app is as follows:
Private Shared QueryShutdown As Integer = &H11
Private Shared systemShutdown As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Messa
If m.Msg = QueryShutdown Then
systemShutdown = True
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.Canc
If (systemShutdown) Then
systemShutdown = False
e.Cancel = False
Else
e.Cancel = True
HideToSysTray()
End If
End Sub