public void Dispose() { IsDisposed = DisposeState.DisposingStarted; cancelToken.Cancel(); if (IoC.inject.Get <InternetStateManager>(this) == this) { IoC.inject.RemoveAllInjectorsFor <InternetStateManager>(); } IsDisposed = DisposeState.Disposed; }
public void Dispose() { IsDisposed = DisposeState.DisposingStarted; client?.Dispose(); handler?.Dispose(); if (IoC.inject.Get <RestFactory>(this) == this) { IoC.inject.RemoveAllInjectorsFor <RestFactory>(); } IsDisposed = DisposeState.Disposed; }
public void Dispose() { IsDisposed = DisposeState.DisposingStarted; fallbackStore.Dispose(); fallbackStore = null; cachedFirstAppLaunchDate = null; cachedLastUpdateDate = null; if (instance == this) { IoC.inject.RemoveAllInjectorsFor <IPreferences>(); } IsDisposed = DisposeState.Disposed; }
public void Dispose() { if (disposeState != DisposeState.Active) { return; } lock (sync) { if (disposeState != DisposeState.Active) { return; } disposeState = DisposeState.Disposing; if (rootItem != null) { try { Ping.Dispose(); } catch (Exception e) { logErr(e); } try { startupSubscription?.Dispose(); startupSubscription = null; } catch (Exception e) { logErr(e); } try { rootItem.Actor.Children.Values .OrderByDescending(c => c.Actor.Id == User) // shutdown "user" first .Iter(c => c.Actor.ShutdownProcess(true)); } catch (Exception e) { logErr(e); } cluster.IfSome(c => c?.Dispose()); } rootItem = null; disposeState = DisposeState.Disposed; } }
/// <summary> /// Releases all instances that are cached by the <see cref="Scope"/> object. /// </summary> /// <param name="disposing">False when only unmanaged resources should be released.</param> protected virtual void Dispose(bool disposing) { if (disposing) { // We completely block the Dispose method from running in parallel, because there's all kinds // of state that needs to be read/written, such as this.state, this.disposables, and // this.scopeEndActions. Making this thread-safe with smaller granular locks will be much // harder and simply not necessarily, since Dispose should normally only be called from one thread. lock (this.syncRoot) { if (this.state != DisposeState.Alive) { // Either this instance is already disposed, or a different thread is currently // disposing it. We can break out immediately. return; } this.state = DisposeState.Disposing; try { this.DisposeRecursively(); } finally { this.state = DisposeState.Disposed; // Remove all references, so we won't hold on to created instances even if the // scope accidentally keeps referenced. This prevents leaking memory. this.cachedInstances = null; this.scopeEndActions = null; this.disposables = null; this.items = null; this.manager?.RemoveScope(this); } } } }
/// <summary> /// Used Internally To Dipose Object. /// </summary> /// <param name="disposing">If true, this method is called because the object is being disposed with the Dispose() method. If false, the object is being disposed by the garbage collector.</param> protected virtual void Dispose(bool disposing) { //Check to see if Dispose has already been called. if ((this._disposeState == DisposeState.None)) { //change the state to Disposing this._disposeState = DisposeState.Disposing; try { //If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { this.DisposeManagedResources(); this.DisposeUnmanagedResources(); this._disposeState = DisposeState.Disposed; this.OnDisposed(); GC.SuppressFinalize(this); } else { this.DisposeUnmanagedResources(); this._disposeState = DisposeState.Disposed; } } catch { this._disposeState = DisposeState.None; throw; } } }