Thursday, September 19, 2013

Service debugging in Windows 8

Prior to Windows 8 you could debug your services by using statements like:
Debugger.Launch();
Now this is being simply ignored. What is reason of that?

Debugger.Launch() would call application with visual user interface. In Windows 8 this is impossible because services can't interact with desktop and run in interactive mode.

To debug service code we added the following code to OnStart method:
while (!Debugger.IsAttached) // waiting until debugger is attached
{
    RequestAdditionalTime(1000);  // prevents the service from timeout
    Thread.Sleep(1000);  // gives you time to attach the debugger
}

No comments:

Post a Comment