我正在调试Windows服务(通过在Visual Studio 2010中点击 F5 ),使用以下代码:
I am debugging a Windows service (by hitting F5 in VisualStudio2010) using the following code:
在Program.cs 文件中:
In Program.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); } }而在MyServer.cs file:
And in MyServer.cs file:
public void StartService() { this.OnStart(new string[0]); }在过去,我使用了 Debug.WriteLine (xxx)在我的所有服务代码中没有任何问题,但现在我注意到所有的 Debug.WriteLine()行不被调用
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.
我清楚地看到调试器正在跳过这些行,当我使用步入( F11 ) - (因此,输出窗口中没有输出文本),而服务在调试模式正确启动。
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".
我不明白为什么不会调用 Debug 代码。建议?
I don't understand why the Debug code won't be called. Suggestions?
我在调试模式下构建我的解决方案(定义DEBUG常量被检查),但是我注意到代码包含 #if DEBUG ... #endif 未被调用。这很奇怪...
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...
推荐答案似乎缺少调试符号。
发生在我身上,这似乎有助于。
Happened to me and this seemed to help.
更多推荐
Debug.WriteLine()没有被打
发布评论