Click here to Skip to main content
16,019,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to debug a windows services without installing it
Posted
Comments
CHill60 13-Mar-13 8:25am    
You'll need to add a little detail. For example is this a 3rd party service or have you written it yourself.
Zoltán Zörgő 13-Mar-13 8:29am    
It is your service (are you currently writing it), or a third party one?

1 solution

I suppose you've written the service on your own?

One debug possibility:

1) Add a method to your service class like:

C#
public partial class YourService : ServiceBase
{
    public void DebugStart()
    {
        this.OnStart(null);
    }

}


And the main should look like this, e.g.

C#
static void Main()
{
    if (System.Environment.UserInteractive)
    {
#if DEBUG
        YourService s = new YourService();
        s.DebugStart();
        
        bool run = true;
        
        do
        {
        // dirty!
           Thread.Sleep(1000);
        } while(run);
        
        
        s.Stop();
        s.Dispose();
#endif
    }
    else
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new YourService() 
        };
        ServiceBase.Run(ServicesToRun);

    }
}


Instead of the dirty forever loop you could open a modal window. To stop the service and debug the service shutdown, set a breakpoint in the forever loop and set run = false.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900