How to debug shutdowns in visual studio?

微笑、不失礼 提交于 2019-12-13 02:57:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!