简体   繁体   中英

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.

据我所知,当您在Visual Studio中结束调试时,该过程只是在没有调用终结器的情况下被杀死,甚至位于finally块中的代码也不会执行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM