Problem on shutdown computer if my appication is opened

  • Thread starter Thread starter Cylix
  • Start date Start date
C

Cylix

I wrote two application for my company,
but I found that, if anyone of application is opened, the user cannot
shutdown the computer.

the behaviour is that:
if one of application is opened, and then click the shutdown, my
application will be terminate but the computer didn't shotdown.
afterward, if I click the shutdown again, since my application is
already terminated, so the computer can shutdown this time.

What the problem is??
 
Cylix said:
I wrote two application for my company,
but I found that, if anyone of application is opened, the user cannot
shutdown the computer.

the behaviour is that:
if one of application is opened, and then click the shutdown, my
application will be terminate but the computer didn't shotdown.
afterward, if I click the shutdown again, since my application is
already terminated, so the computer can shutdown this time.

What the problem is??

I had this happen when; in my application I was aborting the form close
event if there was unsaved data. Apparently setting the cancel property to
true was getting in the way of Windows being allowed to close.



I had to look at the way windows was being asked to close and act
accordingly, then allow the form to close and in turn allow Windows to
close.
 
Thanks Ray,

I have tried to comment the form closing event already, but the
problem still here.
Do you find any solution for this?
 
Do you have any forms that are hidden at the time? They might be causing
issues.
 
Cylix,

Use this code & it will do what you need:

' Exit Windows message
Private Shared WM_QUERYENDSESSION As Integer = &H11


#Region "Window Proc (SUB)"


<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissi
ons.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
' Listen for operating system messages
If m.Msg = WM_QUERYENDSESSION Then
Application.Exit()
End If
' Handle the message
MyBase.WndProc(m)
End Sub
#End Region

I hope this helps,
 
Back
Top