My project simply creates log files that holds the information about the date when the application starts or application exits and how.
Optional Question: How can I add my application to start up list (to msconfig.exe thing)
Optional Question 2: Is there a loss probability when i want to create an only one log file while/before on shutdown?
There is a way to detect why the application is shutting down, but you need to get at the Windows main message loop using p/Invoke. I don’t know the exact message that Windows broadcasts when a shutdown is triggered, but at least I can get you in the right direction.
General information on messages: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632590%28v=vs.85%29.aspx
The
GetMessagefunction: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644936%28v=vs.85%29.aspxI think this is the broadcast message: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632617%28v=vs.85%29.aspx
Doing this from C# is left as an exercise for the reader. It would involve replacing the main message pump provided by WinForms or WPF, inspecting each message, then calling the replaced pump.
I’d start here: Message pumping?