Search code examples
c#-4.0windows-serviceswindows-8

Debugger.Launch() on windows service in Windows 8


After I installed Windows 8 perfectly legit statement like this doesn't work anymore:

#if DEBUG
    Debugger.Launch();
#endif

Service starts ignoring that thing. Yes, I am building the project in a debug mode.

if I change that to a Debugger.Break() - the service just fails, and still there's no dialog for attaching a debugger.


Solution

  • Debugger.Launch would launch an application with a visual GUI. By default services do not interact with a desktop and thus anything they do cannot be "seen".

    Support for interacting with the desktop has slowly been removed from Windows services ("Interact with the desktop" option has been removed from some Server versions for example). I would imagine they've continued this trend.

    Windows Services by nature are not GUI applications, they can run before and after a user logs into a desktop and thus cannot show a GUI all the time. It's not generally a good idea to depend on an ability to have a GUI in a Service.

    If what you want to do is debug a service, I suggest running it as a regular application so that you can do things like Launch and Debug. Shameless plug: you can see Developing Windows Services in Visual Studio for a way to write a service that supports that.