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

时间:2021-09-27 01:32:00

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?

我在Windows服务中使用Microsoft Log Parser。该程序在常规网页中工作,但是当我将代码放在Windows服务中时它不起作用。我把Breakponts放在windows服务中但是当我运行代码时,程序不会在断点处停止。因此,通过我的故障排除,我已将问题缩小到Log Parser软件和Linq。因此Linq或日志解析器软件都会产生问题。你们有什么想法吗?

4 个解决方案

#1


2  

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.

我过去做过很多种方法,取决于程序的运行方式。我认为最简单的方法是在Debugger.Launch()周围使用if #DEBUG预处理器指令,这样当你构建优化的项目时,Debugger.Launch()调用将不会被编译到程序集中。

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.

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

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.

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

#2


5  

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.

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

#3


2  

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.

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

#4


2  

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.

我认为胖猫建议将调试器附加到服务过程听起来是正确的。如果仍然无效,请尝试使用Debug.WriteLine和DebugView。

#1


2  

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.

我过去做过很多种方法,取决于程序的运行方式。我认为最简单的方法是在Debugger.Launch()周围使用if #DEBUG预处理器指令,这样当你构建优化的项目时,Debugger.Launch()调用将不会被编译到程序集中。

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.

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

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.

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

#2


5  

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.

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

#3


2  

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.

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

#4


2  

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.

我认为胖猫建议将调试器附加到服务过程听起来是正确的。如果仍然无效,请尝试使用Debug.WriteLine和DebugView。