banner



How To Debug A Service In Visual Studio

Debugging a windows service is non that straightforward a task as debugging other spider web or windows awarding are in Visual Studio (by merely pressing F5). Instead, we need to practice some tricky tasks to debug information technology equally the service runs under the context of the Service Control Manager. In my inquiry I institute three different ways to debug a windows service.

one. Attaching the debugger to the services's process ( Need to INSTALL the service)

This is a commonly used method.
Steps to use this method:

— Kickoff of all we need to install the service.
— From Service Explorer start the service.
— Then come back to the projection in Visual Studio.
— Go to the Debug carte du jour, select Attach to Process and check Testify processes from all users and Show processes in all sessions then from the Available Processes choice the procedure of that windows service project. [ Note: Brand certain you attach the right procedure, attempting to debug an essential system process may destabilize your organization or crash it]

Eg: If your service name is 'ServiceDemo' then yous can discover a procedure named ServiceDemo.exe, select and attach it.
— Give a breakpoint where yous want to use in the code. Then wait till the breakpoint is hitting for if any timer is specified in the service or else you tin restart the service again.

This method is a bit time taking as to install the service, once again attach the process but to debug it. Fifty-fifty sometimes it doesn't work or shows mistake and nosotros need to restart the system.
2. Using 'Debugger.Launch() / Debugger.Suspension()' methods ( Need to INSTALL the service)
Here yous don't demand to attach any process rather you tin telephone call the Debugger.Launch() or Debugger.Break() method in the OnStart() part.

Eg:

protected override void OnStart(string[] args)  {  #if (DEBUG) // Just to check if its in DEBUG mode or non. As this method works in Release manner too for .Internet 2.0  Debugger.Launch(); // Attaches a debugger to the process. (We can utilize Debugger.Break() also)  

0 Response to "How To Debug A Service In Visual Studio"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel