How to dispose WCF services correctly?
My WCF service is IDisposable
because it开发者_如何学Go uses a ReadWriterLockSlim
. When I dispose both of them in the following method:
public void Dispose()
{
lockSlim.Dispose();
}
Some of the public methods are still running (or accepting new connections, I don't know), and it fires exceptions because of the attempts of using disposed objects (the lockSlim in this case). It would be nicer if, when stopping a Windows Service hosted WCF Service, the Dispose
method was called after stopping all running methods and closing it for new connections. But it seems that it must be done manually. There are any shortcuts or examples?
I think there is no need to dispose LockSlim object. On service stop, call ServiceHost.Close() . all the threads will interrupr its work, all the links will be broken and Garbage colector will take care about the memory. ReadWriterLockSlim is not critical resource. Please let me know if it was helpfull
精彩评论