public void Dispose() { while (!ScopeStack.TryPop(out _)) { Thread.Sleep(100); } }
protected virtual void Dispose(bool disposing) { //本类内部没有封装任何托管或非托管资源,所以无需额外处理,直接维护正确的容器结构即可 if (!_disposed) { if (disposing) { //处理托管资源 if (Item != null) { Item.Dispose(); Item = null; } if (!ScopeStack.IsEmpty) { AmbientScope result; ScopeStack.TryPop(out result); } if (ScopeStack.IsEmpty) { CallContext.FreeNamedDataSlot(_scopeStackKey); } } //处理非托管资源 } _disposed = true; }