K
kevininstructor
I want to prevent a user from closing an application while doing critical
operations. The following code (concept came from MSDN) works except for
when the user attempts to terminate via "Task List" which causes "Program
not responding"...press "Cancel" and no issues, press "End now" and sure
enough it ends.
My question is; is there any method to prevent the "Application not
responding" message from appearing?
Current code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Region " Windows Form Designer generated code "
Private bWasClick As Boolean
Private bAllowExit As Boolean
....
Public Const SC_CLOSE As System.Int32 = 61536
Public Const WM_SYSCOMMAND As System.Int32 = 274
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_CLOSE Then
Me.bWasClick = True
If Me.CheckBox1.Checked Then
Return
End If
End If
MyBase.WndProc(m)
End Sub
....
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged
bAllowExit = DirectCast(sender, CheckBox).Checked()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Me.bWasClick Then
'...
Else
'...
End If
e.Cancel = bAllowExit
End Sub
Visual Studio 1.1
Thanks for any assistance and for taking the time to read this question!
Kevin
operations. The following code (concept came from MSDN) works except for
when the user attempts to terminate via "Task List" which causes "Program
not responding"...press "Cancel" and no issues, press "End now" and sure
enough it ends.
My question is; is there any method to prevent the "Application not
responding" message from appearing?
Current code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Region " Windows Form Designer generated code "
Private bWasClick As Boolean
Private bAllowExit As Boolean
....
Public Const SC_CLOSE As System.Int32 = 61536
Public Const WM_SYSCOMMAND As System.Int32 = 274
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_CLOSE Then
Me.bWasClick = True
If Me.CheckBox1.Checked Then
Return
End If
End If
MyBase.WndProc(m)
End Sub
....
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged
bAllowExit = DirectCast(sender, CheckBox).Checked()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Me.bWasClick Then
'...
Else
'...
End If
e.Cancel = bAllowExit
End Sub
Visual Studio 1.1
Thanks for any assistance and for taking the time to read this question!
Kevin