Don't trap form closing event when computer shutting down

Posted on 2012-09-18
Last Modified: 2012-09-18

I trap my main form from closing and give the user an options box to remind them that the services of the app will no longer work if they close vs. minimize the application (which goes to the systray).  However, when they shut down the computer my application still gives the warning and demands a response before the computer shuts off.  Is there a way to ignore the formclosing event IF the computer is closing the app during the shut down process?

VS 2010
Windows Forms
Windows 7 64, 32 & Win XP 32

Thanks for any thoughts
Question by:zipnotic
    LVL 15

    Accepted Solution

    In your FormClosing event do this check:

        If e.CloseReason <> CloseReason.WindowsShutDown Then
            'give warning
            'don't warn
        End If
    End Sub

    Author Closing Comment

    LVL 15

    Expert Comment

    by:David L. Hansen

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now