本文介绍了Win7 64 位上的 VS2008:调试 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Win7 64 位上使用 VS2008 调试 Windows 服务.我遇到的问题是,无论我选择哪种构建配置:x86、x64 或 AnyCPU,我的断点都没有被击中.

I'm trying to debug a Windows Service using VS2008 on Win7 64-Bit. The problem I'm having is that none of my breakpoints are being hit, regardless of which build configuration I choose: x86, x64 or AnyCPU.

在服务启动后使用附加到进程",没有任何断点被击中 - 但 IDE 不会通知我它们不会被击中(例如,通过制作实心红色圆圈和轮廓)- 看起来好像断点根本不存在一样.

Using "Attach to Process" after the service has started, none of the breakpoints are hit - yet the IDE doesn't inform me that they won't be hit (by making the solid red circle and outline, for instance) - it simply seems to act as if the breakpoints weren't even there.

这里有人能指出我正确的方向吗?

Can anyone point me in the right direction here?

谢谢

/理查德.

推荐答案

明显问题优先...

  • 您是在调试模式还是发布模式下编译?
  • .pdb 文件是否位于您的服务的安装位置?
  • 您确定设置断点的代码实际上正在执行吗?

如果这些都不是问题,请尝试在您的服务的构造函数中插入以下行.

If none of these are issues, try inserting the following line in the constructor for your service.

System.Diagnostics.Debugger.Break();

服务启动时,应该会提示您选择调试器.当调试器打开时,它会在程序断点处暂停,您可以从那里继续.我不使用 Windows 7,但我认为 Visual Studio 2008 的这一方面与 Windows XP 相比没有太大变化.我一直使用这种编程方法为我的 Windows 服务进入调试会话.

When the service starts up, you should be prompted to choose a debugger. When the debugger opens, it'll pause at the programmatic breakpoint, and you can continue from there. I don't work with Windows 7, but I don't expect this aspect of Visual Studio 2008 has changed much from Windows XP. I use this programmatic method all the time to enter a debug session for my Windows service.

这篇关于Win7 64 位上的 VS2008:调试 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 06:31