How to debug windows service which fails in Init() method

若如初见. 提交于 2020-01-02 17:34:27

问题


I have a windows service which fails in Init() method and throws some exception , so only way for me to check what the error is by looking at the event log. I want to debug the windows service, but the problem is that i can attach debugger only when service is rnning, in my case it fails in Init() method only. Any idea ?


回答1:


you can programatically attach the debugger as the first line in the function:

Debugger.Launch ();

after adding the using statement:

using System.Diagnostics;



回答2:


What I usually do is to have a class with a static void Main() entry point, which I can then temporarily assign in the project properties. From there, I call the same startup functions that are called when the app is run as a service.




回答3:


probably you can get the dumps of the crash using DebugDiag or windbg.

is your service C++ or C#.

Also maybe it is just a first chance exception and not really a crash. Can you provide more info on the failure.



来源:https://stackoverflow.com/questions/1914296/how-to-debug-windows-service-which-fails-in-init-method

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