banner



How To Debug Windows Service In Visual Studio 2010

Debugging a windows service is not that straightforward a chore as debugging other web or windows application are in Visual Studio (by but pressing F5). Instead, we demand to exercise some tricky tasks to debug it as the service runs under the context of the Service Control Manager. In my research I found three unlike ways to debug a windows service.

i. Attaching the debugger to the services's process ( Demand to INSTALL the service)

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

— First of all nosotros need to install the service.
— From Service Explorer start the service.
— So come dorsum to the projection in Visual Studio.
— Get to the Debug carte, select Attach to Process and bank check Show processes from all users and Show processes in all sessions then from the Bachelor Processes pick the process of that windows service projection. [ Note: Brand sure y'all attach the correct process, attempting to debug an essential arrangement procedure may destabilize your system or crash information technology]

Eg: If your service name is 'ServiceDemo' so you tin can find a process named ServiceDemo.exe, select and attach information technology.
— Requite a breakpoint where y'all want to employ in the code. And so wait till the breakpoint is hit for if any timer is specified in the service or else you can restart the service again.

This method is a bit fourth dimension taking as to install the service, once more attach the process just to debug information technology. Even sometimes it doesn't piece of work or shows mistake and we need to restart the organisation.
2. Using 'Debugger.Launch() / Debugger.Pause()' methods ( Need to INSTALL the service)
Hither you don't need to adhere any process rather you lot can phone call the Debugger.Launch() or Debugger.Break() method in the OnStart() function.

Eg:

protected override void OnStart(cord[] args)  {  #if (DEBUG) // Just to check if its in DEBUG fashion or non. As this method works in Release mode as well for .Cyberspace ii.0  Debugger.Launch(); // Attaches a debugger to the procedure. (Nosotros can use Debugger.Break() as well)  

0 Response to "How To Debug Windows Service In Visual Studio 2010"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel