52ky 发表于 2022-5-2 11:26:52

关于调试WINDOWS SERVICES的方法

在开发Windows服务的时候,调试起来不是很方便,因为这样的程序是没有屏幕的。

一般调试是在服务启动后通过附加进程进行调试,但是服务启动过程中执行的代码不能通过这种方式进行调试。

另外,在服务的启动方法中加入thread.sleep()方法,让它休眠几秒,这样就有时间通过??attach process方法调试服务启动过程中执行的代码。

不过很高兴最近在博客园看到一个问题,里面提到了一个调试服务的方法,非常简单好用,给了我很多帮助。在此,谢谢大哥。



调试方法:

   在服务的 start() 方法中,添加: System.Diagnostics.Debugger.Launch();这段代码。这样在启动服务时会默认打开vs的调试窗口进行调试,

只需要提前设置断点,是不是很方便?

(When developing windows services, debugging is not very convenient, because such programs have no screen.
Generally, debugging is performed through additional processes after service startup, but the code executed during service startup cannot be debugged in this way.
In addition, add thread. In the service startup method Sleep () method, let it sleep for a few seconds, so that it has time to pass?? The attach process method debugs the code executed during service startup.
I'm very glad to see a lot of simple debugging methods mentioned in the blog recently, but I'm very glad to see a good one. Here, thank you, brother.
Commissioning method:
In the start () method of the service, add: system Diagnostics. Debugger. Launch(); This code. In this way, the debugging window of vs will be opened for debugging by default when starting the service,
Is it convenient to set breakpoints in advance?
)



页: [1]
查看完整版本: 关于调试WINDOWS SERVICES的方法