[软件设计/软件工程] 关于调试WINDOWS SERVICES的方法

[复制链接]
发表于 2022-5-2 11:26:52
在开发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?
)





上一篇:回调机制
下一篇:ANDROID UI开发——实现菜单左右

使用道具 举报

Archiver|手机版|小黑屋|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved( ICP备案粤ICP备14042591号-1粤ICP14042591号 )

关于本站 - 版权申明 - 侵删联系 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

快速回复 返回顶部 返回列表