Debug.WriteLine()没有被打 [英] Debug.WriteLine() is not hit

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

问题描述

我正在调试Windows服务(通过在Visual Studio 2010中点击 F5 ),使用以下代码:

I am debugging a Windows service (by hitting F5 in Visual Studio 2010) 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...

推荐答案

似乎缺少调试符号。


  1. 清理您的解决方案,重新启动Visual Studio,重新构建解决方案。

  2. 确保配置管理器处于调试模式。

  3. 检查工具>选项>调试并取消选中启用我的代码

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

Happened to me and this seemed to help.

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

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