如何在 Visual Studio 中调试 Windows 服务? [英] How do I debug Windows services in Visual Studio?

查看:59
本文介绍了如何在 Visual Studio 中调试 Windows 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Visual Studio 中调试 Windows 服务?

Is it possible to debug the Windows services in Visual Studio?

我使用了类似的代码

System.Diagnostics.Debugger.Break();

但它给出了一些代码错误,例如:

but it is giving some code error like:

我收到两个事件错误:eventID 4096VsJITDebugger 和服务做了不响应启动或控制及时提出要求."

I got two event error: eventID 4096 VsJITDebugger and "The service did not respond to the start or control request in a timely fashion."

推荐答案

你也可以试试这个.

  1. 创建您的 Windows 服务并安装并启动....也就是说,Windows 服务必须在您的系统中运行.
  2. 在您的服务运行时,转到调试菜单,点击附加进程(或旧 Visual Studio 中的进程)
  3. 找到您正在运行的服务,然后确保选择了显示所有用户的进程显示所有会话中的进程,如果没有,则选择它.
  1. Create your Windows service and install and start…. That is, Windows services must be running in your system.
  2. While your service is running, go to the Debug menu, click on Attach Process (or process in old Visual Studio)
  3. Find your running service, and then make sure the Show process from all users and Show processes in all sessions is selected, if not then select it.

  1. 点击附加按钮
  2. 点击确定
  3. 点击关闭
  4. 在您想要的位置设置一个断点并等待执行.只要您的代码达到该点,它就会自动调试.
  5. 记住,把你的断点放在可达的地方,如果是onStart(),则停止并重新启动服务
  1. Click the Attach button
  2. Click OK
  3. Click Close
  4. Set a break point to your desirable location and wait for execute. It will debug automatic whenever your code reaches to that point.
  5. Remember, put your breakpoint at reachable place, if it is onStart(), then stop and start the service again

(经过大量的谷歌搜索,我在如何在 Visual Studio 中调试 Windows 服务"中找到了这个.)

(After a lot of googling, I found this in "How to debug the Windows Services in Visual Studio".)

这篇关于如何在 Visual Studio 中调试 Windows 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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