Click to See Complete Forum and Search --> : Program to detect windows shut down


makdu
January 7th, 2010, 05:08 AM
Hi,
I have an application and this application needs to close when the window shutdown happen. How can i detect that the system is shutting down from a C# program

dannystommen
January 7th, 2010, 05:17 AM
if it is a windows application, use the FormClosing event


private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
if (e.CloseReason == CloseReason.WindowsShutDown) {
//
}
}

boudino
January 7th, 2010, 05:39 AM
Subscribe to the event System.Events.SessionEnded (http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionended.aspx).