/// <inheritdoc /> public Task DisposeAsync(CancellationToken cancellationToken) { if (!IsTemporaryLock) { return(Task.FromResult(0)); } // A temporary lock is always on its own var l = OwnedLocks.Single(); // Ignore errors, because the only error that may happen // is, that the lock already expired. return(_lockManager.ReleaseAsync(l.Path, new Uri(l.StateToken, UriKind.RelativeOrAbsolute), cancellationToken)); }
/// <inheritdoc/> protected override async Task DisposeAsyncCore() { // Under tree lock here, until first await. EnsureTreeLocked(); try { if (_locks.Any(x => !(x is IxInstanceChildLock))) { Critical.Assert( false, "Dependencies schema problem, after instance object disposed no any lock are allowed."); } if (!ObjectCreationTask.IsFaulted) { // Only fully-initialized instance should be self-disposed. await SelfDispose(); } // This call is not required. ////UpdateChildrenDisposeCompleteSuspendState(); _childrenDisposeCompleted.Set(); // Sync or async execution here. } finally { // Sync or async execution here. // ------------------------------------ lock (ProviderNode.Host.InstanceTreeSyncRoot) { // Freeing all owned locks. while (OwnedLocks.Any()) { // Here other objects can dispose synchronously. OwnedLocks.First().Dispose(); } } await _childrenDisposeCompleted; } }