我正在调试 Windows 服务(通过点击F5
在 Visual Studio 2010 中)使用以下代码:
In 程序.cs file:
static void Main() {
if (!Environment.UserInteractive) {
// We are not in debug mode, startup as service
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new MyServer() };
ServiceBase.Run(ServicesToRun);
}
else {
// We are in debug mode, startup as application
MyServer service = new MyServer();
service.StartService();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
}
And in MyServer.cs file:
public void StartService() {
this.OnStart(new string[0]);
}
过去,我使用Debug.WriteLine("xxx")
我的所有服务代码中都没有任何问题,但现在我注意到所有Debug.WriteLine()
不再调用线路。
当我使用以下命令进行调试时,我清楚地看到调试器正在跳过这些行步入 (F11
) - (因此,输出窗口上没有输出文本),而服务正确启动于“调试模式”.
我不明白为什么Debug
代码不会被调用。建议?
我在调试模式下构建我的解决方案(Define DEBUG constant
已检查),但我注意到代码周围是#if DEBUG ... #endif
不被调用。这很奇怪...
似乎缺少调试符号。
- 清理您的解决方案,重新启动 Visual Studio,重建解决方案。
- 确保配置管理器处于调试模式。
- 签入“工具”>“选项”>“调试”并取消选中“仅启用我的代码”
发生在我身上,这似乎有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)