Debug.WriteLine()没有被打

编程入门 行业动态 更新时间:2024-10-20 21:00:21
本文介绍了Debug.WriteLine()没有被打的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

推荐答案

似乎缺少调试符号。

  • 清理您的解决方案,重新启动Visual Studio,重新构建解决方案。
  • 确保配置管理器处于调试模式。
  • 检查工具>选项>调试并取消选中启用我的代码
  • 发生在我身上,这似乎有助于。

    Happened to me and this seemed to help.

    更多推荐

    Debug.WriteLine()没有被打

    本文发布于:2023-05-28 12:31:53,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/320952.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Debug   WriteLine

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!