Echilon
Echilon

Reputation: 10264

Debugging Stopping a Windows Service

I'm debugging a windows service in VS2010 with:

static void Main()
{
    #if (DEBUG)
        var s1 = new Service1();
        s1.Start();
        Thread.Sleep(Timeout.Infinite);
    #else
        ServiceBase.Run(new ServiceBase[] 
            { 
                new Service1() 
            });
    #endif
}

This lets me run the service in the debugger. The problem is that on starting, the service opens a WCF channel which seems to tie up a socket after I kill the process by stopping debugging. How do I close this socket when I stop debugging or if the service is stopped. I tried setting breakpoints in the service destructor, and both the OnStop and OnShutdown methods, but these aren't called.

Upvotes: 2

Views: 1742

Answers (1)

Tony Kh
Tony Kh

Reputation: 1572

As far as I know when you end debugging in Visual Studio, the process is just killed without calls to finalizers and even code located finally blocks is not executed.

Upvotes: 1

Related Questions