问题
As part of my work I am trying to do some processing when the OS is shutdown. To do this, I found this resource.
It supposed to explain how to do this but for events like a OS shutdown it uses Debug.Writeline
.
But how can you see the Debug in your visual studio if the system is shutting down? I can not imagine how.
Naively I tried, and visual studio gave me an unrecoverable error
The resource is the book C# Cookbook and the recipe 19.1 Dealing with Operating System Shutdown, Power management or user session changes. They suggest to implement a function public static void RegisterForSystemEvents()
(using Win32.SystemEvents) where you will hook up event handlers to capture these events for example
SystemEvents.SessionEnding+= new SessionEndingEventHandler(OnSessionEnding)
and inside these they put Debug.WriteLine as in
private static void OnSessionEnding(object sender, SessionEndingEventArgs e)
{
e.Cancel=false;
Debug.WriteLine("some message here");
}
The thing is how can you see these debug messages if the OS is shutting down?
来源:https://stackoverflow.com/questions/48763706/how-to-debug-shutdowns-in-visual-studio