Solved

Windows wont Shutdown when running my App

Posted on 2004-08-11
3
295 Views
Last Modified: 2010-04-23
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.CancelEventArgs) 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
0
Comment
Question by:jazduck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Author Comment

by:jazduck
ID: 11780406
Solved this one myself.  My afterthought was the way to go.

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.Message)
        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.CancelEventArgs) Handles MyBase.Closing
        If (systemShutdown) Then
            systemShutdown = False
            e.Cancel = False
        Else
            e.Cancel = True
            HideToSysTray()
        End If
    End Sub
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11804841
User resolved; closed, 150 points refunded.

Netminder
Site Admin
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question