Turning off closing closes my application

Is it possible in .NET to find out if my application closes due to the fact that Windows receives the shutdown command (as opposed to closing any old application) to either write out some temporary cache files or even block the shutdown for a long time to request user input?

While my current scope is related to the Winform application and the Windows service, I am interested in understanding this, if possible,

+5
source share
3 answers

SystemEvents.SessionEnding seems like a good starting point for you. This article discusses the sequence of events that occurs when you log out / log out.

+7
source

In general, you need to process a WM_QUERYENDSESSIONWindows message . This will give your application the ability to perform a cleanup or block shutdown if it is really necessary.

+4
source

Handle the SessionEnded event in type Microsoft.Win32.SystemEvents.

+2
source

All Articles