WCF ServiceHost.Close() Delay

Jasper Chan picture Jasper Chan · Jun 22, 2009 · Viewed 9.7k times · Source

I have a simple WCF duplex TCP service that I am trying to stop programmatically. If I don't have any connected users, ServiceHost.Close() is very quick but if I even have one connected user, I find the Close() function to take quite a bit of time, sometimes >30seconds. Is this usual behavior?

On the other hand, Abort() is almost instantaneous and I am tempted to use that instead.

Answer

Scott Weinstein picture Scott Weinstein · Jun 22, 2009

It may be. The docs state that

The Close method allows any unfinished work to be completed before returning. For example, finish sending any buffered messages.

There is an overload to Close() which takes a TimeSpan (and throws if the timespan is exceeded)

Abort() looks like the best way to stop a WCF host without delay.