/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public override void Dispose() { #if DEBUG GC.SuppressFinalize(this); #endif foreach (var observeChangesAndEvictItemsFromCacheForDatabase in observeChangesAndEvictItemsFromCacheForDatabases) { observeChangesAndEvictItemsFromCacheForDatabase.Value.Dispose(); } var tasks = new List <Task>(); foreach (var databaseChange in databaseChanges) { var remoteDatabaseChanges = databaseChange.Value as RemoteDatabaseChanges; if (remoteDatabaseChanges != null) { tasks.Add(remoteDatabaseChanges.DisposeAsync()); } else { using (databaseChange.Value as IDisposable) { } } } foreach (var replicationInformer in replicationInformers) { replicationInformer.Value.Dispose(); } // try to wait until all the async disposables are completed Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(3)); if (Subscriptions != null) { Subscriptions.Dispose(); } if (AsyncSubscriptions != null) { AsyncSubscriptions.Dispose(); } // if this is still going, we continue with disposal, it is for grace only, anyway if (jsonRequestFactory != null) { jsonRequestFactory.Dispose(); } WasDisposed = true; var afterDispose = AfterDispose; if (afterDispose != null) { afterDispose(this, EventArgs.Empty); } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public override void Dispose() { #if DEBUG GC.SuppressFinalize(this); #endif foreach (var observeChangesAndEvictItemsFromCacheForDatabase in observeChangesAndEvictItemsFromCacheForDatabases) { observeChangesAndEvictItemsFromCacheForDatabase.Value.Dispose(); } var tasks = new List <Task>(); foreach (var databaseChange in databaseChanges) { var remoteDatabaseChanges = databaseChange.Value as RemoteDatabaseChanges; //TODO iftah /*if (remoteDatabaseChanges != null) * { * tasks.Add(remoteDatabaseChanges.DisposeAsync()); * } * else * { * using (databaseChange.Value as IDisposable) { } * }*/ } // try to wait until all the async disposables are completed Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(3)); // if this is still going, we continue with disposal, it is for graceful shutdown only, anyway //return unused hilo keys AsyncHelpers.RunSync(() => _asyncMultiDbHiLo?.ReturnUnusedRange()); Subscriptions?.Dispose(); AsyncSubscriptions?.Dispose(); WasDisposed = true; AfterDispose?.Invoke(this, EventArgs.Empty); }