Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6174339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:44:14+00:00 2026-05-23T23:44:14+00:00

I need to detect when Windows is shutdown (or restarted) or when the user

  • 0

I need to detect when Windows is shutdown (or restarted) or when the user is logging off. I need to properly close the application before the application is closed.
I noticed that no exit application event is raised when Windows is closing day.

I read the post Is there a way in c# to detect a Windows shutdown/logoff and cancel that action (after asking the user)

but I’m not sure of where I should perform the operations before closing.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:44:15+00:00Added an answer on May 23, 2026 at 11:44 pm

    Attach an event handler method to the SystemEvents.SessionEnding event, and your handler method will be called each time the event is raised. Handling this event will allow you to cancel the pending log off or shut down, if you wish. (Although that doesn’t actually work like it sounds in current operating systems; for more information see the MSDN documentation here.)

    If you don’t want to cancel the event, but just react to it appropriately, you should handle the SystemEvents.SessionEnded event instead.

    You must make sure that you detach your event handlers when the application is closed, however, because both of these are static events.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a windows script I am writing, I need to detect if the machine
I need to detect whether my application is running within a virtualized OS instance
I need to detect information about the Application Server my EJBs are running in.
I need to detect whether the user has pressed the dot key in the
I have a windows mobile 5 program (compact framework 3.5) that I need to
I need to detect when a new drive is plugged into a Windows system
In a Windows Service, I need to detect when the computer goes into sleep
I'm trying to build a regular expression that will detect any character that Windows
I have a Windows message loop. I need to detect when the screen powers
I need to build an installer for my application (using Windows Installer technology -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.