/// <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 this is still going, we continue with disposal, it is for graceful shutdown only, anyway Subscriptions?.Dispose(); AsyncSubscriptions?.Dispose(); WasDisposed = true; AfterDispose?.Invoke(this, EventArgs.Empty); jsonRequestFactory?.Dispose(); }
/// <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); }
private void OnAfterDispose() { AfterDispose?.Invoke(this, new EventArgs()); }
/// <summary> /// Invokes the AfterDispose event. /// </summary> internal void DoAfterDispose() { AfterDispose.Invoke(); }