Win7 64位上的VS2008:调试Windows服务

时间:2022-09-01 10:01:09

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.

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

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.

在服务启动后使用“Attach to Process”,没有任何断点被击中 - 但是IDE并没有告诉我它们不会被击中(例如通过制作纯红色圆圈和轮廓) - 它只是似乎就好像断点并不存在。

Can anyone point me in the right direction here?

任何人都能指出我在正确的方向吗?

Thanks

/Richard.

3 个解决方案

#1


2  

Obvious questions first...

首先是明显的问题......

  • Are you compiling in debug mode or release mode?
  • 您是在调试模式还是在发布模式下编译?

  • Are the .pdb files located where your service is installed from?
  • .pdb文件是否位于安装服务的位置?

  • Are you sure the code where your breakpoints are set is actually being executed?
  • 您确定设置断点的代码实际上正在执行吗?

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

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

System.Diagnostics.Debugger.Break();

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.

服务启动时,系统会提示您选择调试器。当调试器打开时,它将在程序断点处暂停,您可以从那里继续。我不使用Windows 7,但我不认为Visual Studio 2008的这方面已经从Windows XP发生了很大变化。我一直使用这种编程方法为我的Windows服务输入调试会话。

#2


0  

I know this doesn't answer your direct question but we found this approach from Eric De Carufel to be very helpful when developing and testing Window Services.

我知道这并没有回答你的直接问题,但我们发现Eric De Carufel的这种方法在开发和测试Window Services时非常有用。

It is non intrusive and get rid of the tedious 'attach to process' step.

它是非侵入性的,摆脱了繁琐的“附加到过程”步骤。

The ability to put it into debug when already deployed as Windows Service is also valuable. For example to see the stack trace instead of the service just dying on you.

在已部署为Windows服务时将其置于调试中的能力也很有价值。例如,要查看堆栈跟踪而不是刚刚死于您的服务。

#3


-1  

Are you running Visual Studio as an administrator (incl. launched elevated under UAC)?

您是否以管理员身份运行Visual Studio(包括在UAC下启动)?

#1


2  

Obvious questions first...

首先是明显的问题......

  • Are you compiling in debug mode or release mode?
  • 您是在调试模式还是在发布模式下编译?

  • Are the .pdb files located where your service is installed from?
  • .pdb文件是否位于安装服务的位置?

  • Are you sure the code where your breakpoints are set is actually being executed?
  • 您确定设置断点的代码实际上正在执行吗?

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

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

System.Diagnostics.Debugger.Break();

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.

服务启动时,系统会提示您选择调试器。当调试器打开时,它将在程序断点处暂停,您可以从那里继续。我不使用Windows 7,但我不认为Visual Studio 2008的这方面已经从Windows XP发生了很大变化。我一直使用这种编程方法为我的Windows服务输入调试会话。

#2


0  

I know this doesn't answer your direct question but we found this approach from Eric De Carufel to be very helpful when developing and testing Window Services.

我知道这并没有回答你的直接问题,但我们发现Eric De Carufel的这种方法在开发和测试Window Services时非常有用。

It is non intrusive and get rid of the tedious 'attach to process' step.

它是非侵入性的,摆脱了繁琐的“附加到过程”步骤。

The ability to put it into debug when already deployed as Windows Service is also valuable. For example to see the stack trace instead of the service just dying on you.

在已部署为Windows服务时将其置于调试中的能力也很有价值。例如,要查看堆栈跟踪而不是刚刚死于您的服务。

#3


-1  

Are you running Visual Studio as an administrator (incl. launched elevated under UAC)?

您是否以管理员身份运行Visual Studio(包括在UAC下启动)?