在 Visual Studio 2008 中调试 Windows 服务程序的最佳方法是什么

发布于 2024-08-08 12:59:09 字数 195 浏览 1 评论 0原文

我在 Windows 服务中使用 Microsoft 日志解析器。该程序可以在常规网页中运行,但是当我将代码放入 Windows 服务中时,它无法运行。我将断点放在 Windows 服务中,但是当我运行代码时,程序不会在断点处停止。因此,通过故障排除,我已将问题范围缩小到 Log Parser 软件和 Linq。因此,Linq 或日志解析器软件会造成问题。你们有什么想法吗?

I am using the Microsoft Log Parser in a Windows Service. The program works in a regular web page but when I put the code in a windows service it does not work. I put Breakponts in the windows service but when I run the code the program does not stop at the breakpoint. So through out my troubleshooting I have narrowed the problem down to the Log Parser software and Linq. So either Linq or the log parser software is creating the problem. Do you guys have any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏天碎花小短裙 2024-08-15 12:59:09

您需要将调试器直接附加到 Windows 服务。这可能对您有帮助: http://msdn.microsoft .com/en-us/library/7a50syb3%28VS.80%29.aspx

You need to attach your debugger directly with Windows Services. This might help you: http://msdn.microsoft.com/en-us/library/7a50syb3%28VS.80%29.aspx.

苦妄 2024-08-15 12:59:09

过去我已经通过多种方式完成了此操作,具体取决于程序的运行方式。我认为最简单的方法是在 Debugger.Launch() 周围使用 if #DEBUG 预处理器指令来完成,这样当您构建优化的项目时, Debugger.Launch() 调用将不会被编译到程序集中。

我们完成此任务的一种方法是使用 System.Windows.Forms.MessageBox.Show("attach"),它允许我们在显示“attach”对话框时手动附加到调试器。

我不喜欢的最后一种方法是根据传入的命令行参数更改服务的行为。基本上选择不在特定参数被触发时使用 ServiceBase.Run 启动服务,而是调用封装该行为的类/服务的主要功能。

I have done this many ways in the past depending on how the program runs. I think the easiest way is done with a if #DEBUG preprocessor directive around the Debugger.Launch() that way when you've built the project optimized the Debugger.Launch() call won't be compiled into the assembly.

One way we have also done done this task is with System.Windows.Forms.MessageBox.Show("attach") which allowed us to manually attach to the debugger whenever the "attach" dialog was displayed.

The last way which I do not prefer is to change the behavior of your service based on commandline params passed in. Basically opting NOT to start the services using ServiceBase.Run whenever a particular param was fired off, but calling a class that encapsulates the behavior/main function of the service.

最终幸福 2024-08-15 12:59:09

您想调试 OnStart 方法吗?如果是这样,您可以使用 System.Diagnostics.Debugger.Launch()
或 System.Diagnostics.Debugger.Break() 方法,以便有机会在 on start 方法运行时附加调试器,否则附加调试器总是太晚。

Do you want to debug the OnStart method? If so you can use System.Diagnostics.Debugger.Launch()
or System.Diagnostics.Debugger.Break() method to get a chance to attach the debugger while the on start method is running, otherwise you're always to late with attaching the debugger.

阳光下慵懒的猫 2024-08-15 12:59:09

我认为胖猫关于将调试器附加到服务进程的建议听起来是正确的。如果仍然不起作用,请尝试使用 Debug.WriteLine调试视图

I think fat cat's suggestion of attaching your debugger to the service process sounds right. If that still doesn't work, try using Debug.WriteLine and DebugView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文