/// Decrements the reference count for currently active environment and shuts down the gRPC environment if reference count drops to zero.
/// (and blocks until the environment has been fully shutdown).
/// Decrements the reference count for currently active environment and asynchronously shuts down the gRPC environment if reference count drops to zero.
/// </summary>
internalstaticvoidRelease()
internalstaticasyncTaskReleaseAsync()
{
GrpcEnvironmentinstanceToShutdown=null;
lock(staticLock)
{
GrpcPreconditions.CheckState(refCount>0);
refCount--;
if(refCount==0)
{
instance.Close();
instanceToShutdown=instance;
instance=null;
}
}
if(instanceToShutdown!=null)
{
awaitinstanceToShutdown.ShutdownAsync();
}
}
internalstaticintGetRefCount()
@ -223,13 +229,13 @@ namespace Grpc.Core
/// <summary>
/// Shuts down this environment.
/// </summary>
privatevoidClose()
privateasyncTaskShutdownAsync()
{
if(isClosed)
{
thrownewInvalidOperationException("Close has already been called");