的Debug.WriteLine()不打 [英] Debug.WriteLine() is not hit

查看:157
本文介绍了的Debug.WriteLine()不打的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我调试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...

推荐答案

好像调试符号缺失。

  1. 清洁解决方案,重新启动Visual Studio,重新生成解决方案。
  2. 确保配置管理器处于调试模式。
  3. 检查工具>选项>调试,并取消选中启用仅我的code

发生在我身上,这似乎帮助。

Happened to me and this seemed to help.

这篇关于的Debug.WriteLine()不打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆