我调试Windows服务(通过按 F5
在VS 2010中),使用下面的code:
I am debugging a Windows service (by hitting F5
in VS 2010) using the following code:
在的Program.cs 的文件:
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);
}
}
和中的 MyServer.cs 的文件:
public void StartService() {
this.OnStart(new string[0]);
}
在过去,我用了的Debug.WriteLine(XXX)
行没有在我所有的服务code任何问题,但现在我发现所有的的Debug.WriteLine()
行不叫了。
我清楚地看到,调试器跳过这些行,当我调试用的步入的( F11
) - (因此,没有输出文字输出窗口),而服务是正确启动的调试模式的。
In the past, I used the Debug.WriteLine("xxx")
line without any problem in all my service code but now I noticed that all Debug.WriteLine()
lines are not called anymore.
I clearly see that the debugger is jumping over these lines when I debug with Step Into (F11
) - (thus, there is no output text on the output Window), whereas the service is correctly started in "debug mode".
我不明白为什么调试
code就不会被调用,建议?
I don't understand why the Debug
code won't be called, suggestions?
编辑:
我建立我在调试模式下的解决方案(定义DEBUG常数
被选中),但我注意到,code包围#如果DEBUG ... #ENDIF
不叫。这是奇怪的...
EDIT :
I build my solution in debug mode (Define DEBUG constant
is checked) but I noticed that the code surrounded by #if DEBUG ... #endif
is not called. That is weird...
推荐答案
好像调试符号缺失。
清洁解决方案,重新启动Visual Studio,重新生成解决方案。 确保配置管理器处于调试模式。 检查工具>选项>调试,并取消选中启用仅我的code发生在我身上,这似乎帮助。
Happened to me and this seemed to help.
相关推荐
最新文章