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?
Start Visual Studio with administrative credentials so you can attach to system processes. (Optional) On the Visual Studio menu bar, choose Tools, Options. In the Options dialog box, choose Debugging, Symbols, select the Microsoft Symbol Servers check box, and then choose the OK button.
To debug without installing, add the code as follow, mainly #if (! DEBUG). You will be able to step through the code when you run the Windows Service without installing.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With