Hi,
I want to create an application which works when system is shutting down. So, my question is that is it right way to implement Environment.HasShutdownStarted property for my propose..?
SystemEvents.SessionEnding +=
new SessionEndingEventHandler(SystemEvents_SessionEnding);
void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
if (Environment.HasShutdownStarted)
{
//…………………………
}
else
{
//………………
}
}

VulpesRank #55 · 29.2K reputationPosted Aug 2, 2011, 12:27 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Aug 1, 2011, 11:54 PM EDT
You should test your application very carefully because applications probably often see ghosts in MS operating systems when system is shutting down.
Zoran
Sam HobbsRank #107 · 20.5K reputationPosted Aug 2, 2011, 3:45 PM EDT
Note that your question is not a C# language question. I am not sure what forum would be most appropriate but you really should specify what type of program this is for. Assuming this is a Windows Forms application, you can override the Form.WndProc Method. In a console application you can probably use the IMessageFilter Interface but you will need to do something, such as create a form, to create a message loop.
Okay?
Thomas Mapother156 reputationPosted Aug 2, 2011, 7:46 PM EDT