Search code examples
.netdebuggingwindows-servicesonstart

Installing a WindowsService for debugging


I am trying to start my debug build WindowsService but am getting the error that it didn't start in a timely fashion.

I've cleaned up the ctor and OnStart but still it won't start so I am thinking maybe the dll it loads needs to be better installed, rather than just in the debug directory of my project directory. Maybe all that bumpf in main() is hanging it out to dry?

Any pointers for debugging the service? I can't run it directly in the VStudio because obviously that doesn't permit entry to its OnCustomCommand(int cmd) member and breaks it there.


Solution

  • If I understand correctly, you want to be able to debug the service before it's sitting in it's idle "Started" state?

    You can use Debugger.Break() function for this. For example, we often put the following into our Main function while in a debug build:

    #if DEBUG
    
    if (!Debugger.IsAttached)
    {
        Debugger.Break();
    }
    
    #endif