/// <summary> /// Releases the managed resources (<see cref="managedResource"/>) used in this class. /// </summary> protected override void ReleaseManagedResources() { // Dispose of our managed resource if it is not null. managedResource?.Dispose(); // Call the base method. base.ReleaseManagedResources(); }
public void Dispose() { if (disposed) { throw new ObjectDisposedException(typeof(ActionDisposable).Name); } Disposable?.Dispose(); Disposable = null; disposed = true; }
/// <summary> /// <see cref="IDisposable.Dispose"/> /// </summary> public void Dispose() { this.disposed = true; foreach (KeyValuePair <UdpClient, IPEndPoint> P in this.ssdpOutgoing) { try { P.Key.Dispose(); } catch (Exception) { // Ignore } } this.ssdpOutgoing.Clear(); foreach (UdpClient Client in this.ssdpIncoming) { try { Client.Dispose(); } catch (Exception) { // Ignore } } this.ssdpIncoming.Clear(); foreach (ISniffer Sniffer in this.Sniffers) { if (Sniffer is IDisposable Disposable) { try { Disposable.Dispose(); } catch (Exception ex) { Log.Critical(ex); } } } }
protected override void Dispose(bool disposing) { if (disposing) { Disposable.Dispose(ref _firstDisposable); Disposable.Dispose(ref _secondDisposable); // clearing the queue should happen under the lock // as they are plain Queue<T>s, not concurrent queues. lock (_gate) { _firstObserver.Dispose(); _secondObserver.Dispose(); } } base.Dispose(disposing); }
public void Dispose() { if (Image != null) { Image.Dispose(); } if (symbol_reader != null) { symbol_reader.Dispose(); } if (assembly_resolver.value != null) { assembly_resolver.Dispose(); } }
private static void Tick(object state) { var timer = (Timer)state; try { var timerState = timer._state; if (timerState != DisposedState) { timer._action(timerState); } } finally { Disposable.Dispose(ref timer._timer); } }
public void Dispose_TEST() { tlog.Debug(tag, $"DisposableWithDisposable START"); try { Disposable disposable = new Disposable(); disposable.Dispose(); } catch (Exception e) { tlog.Error(tag, "Caught Exception" + e.ToString()); Assert.Fail("Caught Exception" + e.ToString()); } tlog.Debug(tag, $"DisposableWithDisposable END (OK)"); }
/// <summary> /// Finalizes an instance of an actor. /// </summary> public override Task FinalizeInstance() { this.client?.Dispose(); this.client = null; if (!(this.sniffer is null)) { if (this.sniffer is IDisposable Disposable) { Disposable.Dispose(); } this.sniffer = null; } return(Task.CompletedTask); }
public override void OnCompleted() { Disposable.Dispose(ref _serialCancelable); lock (_gate) { if (_hasValue) { ForwardOnNext(_value !); } ForwardOnCompleted(); _hasValue = false; _id = unchecked (_id + 1); } }
/// <summary> /// Disposes of attached content, given its ID. /// </summary> /// <param name="ContentId">Content ID</param> /// <returns>If content with the corresponding ID was found and disposed.</returns> public bool DisposeContent(string ContentId) { if (this.attachments.TryGetValue(ContentId, out object Obj)) { this.attachments.Remove(ContentId); if (Obj is IDisposable Disposable) { Disposable.Dispose(); } return(true); } else { return(false); } }
internal void CloseTab_Executed(object sender, ExecutedRoutedEventArgs e) { int i = this.Tabs.SelectedIndex; if (i > 0) { if (this.Tabs.Items[i] is TabItem TabItem) { object Content = TabItem.Content; if (Content != null && Content is IDisposable Disposable) { Disposable.Dispose(); } } this.Tabs.Items.RemoveAt(i); } }
public void Merge_repeated_code_snd_test_only_one_thing() { // Execute after dispose. Assert.Throws <ObjectDisposedException>( () => { var sut = new Disposable(); sut.Dispose(); sut.Execute(); }); // Repeated dispose Assert.Throws <ObjectDisposedException>( () => { var sut = new Disposable(); sut.Dispose(); sut.Dispose(); }); }
private void OnCompleted(int index) { lock (_gate) { _isDone[index] = true; if (_isDone.All()) { ForwardOnCompleted(); } else { var subscriptions = Volatile.Read(ref _subscriptions); if (subscriptions != null && subscriptions != Array.Empty <IDisposable>()) { Disposable.Dispose(ref subscriptions[index]); } } } }
// Section 10.14.4.3 public void Dispose() { switch (state) { case State.Before: state = State.After; break; case State.Running: break; // unspecified case State.Suspended: { state = State.Running; // finally occurs here d.Dispose(); state = State.After; } break; case State.After: return; default: return; // can't happen } }
/// <summary> /// Disposes contained objects and releases resources used by the <see cref="LifetimeContainer"/>. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { object[] array; lock (objects) { array = objects.ToArray(); objects.Clear(); } for (int i = array.Length - 1; i >= 0; i--) { Disposable.Dispose(array[i]); } OnDisposed(); } }
public void OnCompleted() { lock (_parent._gate) { _parent._samplerAtEnd = true; if (_parent._hasValue) { _parent._hasValue = false; _parent.ForwardOnNext(_parent._value); } if (_parent._sourceAtEnd) { _parent.ForwardOnCompleted(); } else { Disposable.Dispose(ref _parent._samplerDisposable); } } }
public void ObserveAdded() { var a = new Set <int>(); a.Add(1); a.Add(2); var b = new Set <int>(); b.Add(4); b.Add(8); var proxy = new SetProxy <int>(); var sum = 0; var observers = new Disposable() .Add(proxy.Added(item => sum += item)) .Add(proxy.Removed(item => sum -= item)); proxy.Target = a; Assert.AreEqual(3, sum); a.Remove(1); Assert.AreEqual(2, sum); proxy.Target = b; Assert.AreEqual(12, sum); b.Add(1); Assert.AreEqual(13, sum); proxy.Target = null; Assert.AreEqual(0, sum); b.Remove(8); proxy.Target = b; Assert.AreEqual(5, sum); observers.Dispose(); b.Add(7); proxy.Target = null; Assert.AreEqual(5, sum); }
protected override void Dispose(bool disposing) { if (disposing) { var subscriptions = Interlocked.Exchange(ref _subscriptions, Array.Empty <IDisposable>()); if (subscriptions != null && subscriptions != Array.Empty <IDisposable>()) { for (var i = 0; i < subscriptions.Length; i++) { Disposable.Dispose(ref subscriptions[i]); } lock (_gate) { foreach (var q in _queues) { q.Clear(); } } } } base.Dispose(disposing); }
/// <summary> /// Returns an instance of the type <paramref name="Type"/>. /// </summary> /// <param name="ReturnNullIfFail">If null should be returned instead for throwing exceptions.</param> /// <param name="Type">Type of objects to return.</param> /// <param name="Arguments">Constructor arguments.</param> /// <returns>Instance of <paramref name="Type"/>.</returns> public object Instantiate(bool ReturnNullIfFail, Type Type, params object[] Arguments) { SingletonKey Key = new SingletonKey(Type, Arguments); object Object; lock (instances) { if (instances.TryGetValue(Key, out Object)) { return(Object); } } Object = Types.Create(ReturnNullIfFail, Type, Arguments); if (Object is null) { return(null); } lock (instances) { if (instances.TryGetValue(Key, out object Object2)) { if (Object is IDisposable Disposable) { Disposable.Dispose(); } return(Object2); } instances[Key] = Object; } return(Object); }
private void Drain() { if (Interlocked.Increment(ref _trampoline) != 1) { return; } for (; ;) { if (Volatile.Read(ref _isDisposed)) { while (_stack.Count != 0) { var enumerator = _stack.Pop(); enumerator.Dispose(); } Disposable.Dispose(ref _currentSubscription); } else { if (_stack.Count != 0) { var currentEnumerator = _stack.Peek(); var currentObservable = default(IObservable <TSource>); try { if (currentEnumerator.MoveNext()) { currentObservable = currentEnumerator.Current; } } catch (Exception ex) { currentEnumerator.Dispose(); ForwardOnError(ex); Volatile.Write(ref _isDisposed, true); continue; } IObservable <TSource>?next; try { next = Unpack(currentObservable); } catch (Exception ex) { if (!Fail(ex)) { Volatile.Write(ref _isDisposed, true); } continue; } if (next != null) { var nextSeq = Extract(next); if (nextSeq != null) { if (TryGetEnumerator(nextSeq, out var nextEnumerator)) { _stack.Push(nextEnumerator); continue; } Volatile.Write(ref _isDisposed, true); continue; } // we need an unique indicator for this as // Subscribe could return a Disposable.Empty or // a BooleanDisposable var sad = ReadyToken.Ready; // Swap in the Ready indicator so we know the sequence hasn't been disposed if (Disposable.TrySetSingle(ref _currentSubscription, sad) == TrySetSingleResult.Success) { // subscribe to the source var d = next.SubscribeSafe(this); // Try to swap in the returned disposable in place of the Ready indicator // Since this drain loop is the only one to use Ready, this should // be unambiguous var u = Interlocked.CompareExchange(ref _currentSubscription, d, sad); // sequence disposed or completed synchronously if (u != sad) { d.Dispose(); if (u == BooleanDisposable.True) { continue; } } } else { continue; } } else { _stack.Pop(); currentEnumerator.Dispose(); continue; } } else { Volatile.Write(ref _isDisposed, true); Done(); } } if (Interlocked.Decrement(ref _trampoline) == 0) { break; } }
public void Dispose() { pdb_file.Dispose(); }
public void Dispose() { Disposable.Dispose(); }
public void Dispose() { Stream.Dispose(); }
public void Dispose() { _cancellationTokenSource.Dispose(); Disposable.Dispose(); }
public void Dispose() => backing.Dispose();
/// <summary> /// アプリが閉じられる時 /// </summary> private void Close() { Disposable.Dispose(); }
public void Run() { var disposable = new Disposable(); disposable.Dispose(); Assert.IsTrue(DisposeTracker.HasDisposedBeenCalled); }
public void Dispose() { Disposable.Dispose(ref _cancel); }
/// <summary> /// Stops the gateway. /// </summary> public static void Stop() { IDisposable Disposable; Log.Informational("Server shutting down."); /* * if (databaseProvider != null) * File.WriteAllText(appDataFolder + "Stop.xml", databaseProvider.ExportXml(true).Result); */ if (gatewayRunning != null) { gatewayRunning.Release(); gatewayRunning.Dispose(); gatewayRunning = null; } if (ibbClient != null) { ibbClient.Dispose(); ibbClient = null; } if (httpxServer != null) { httpxServer.Dispose(); httpxServer = null; } if (provisioningClient != null) { provisioningClient.Dispose(); provisioningClient = null; } if (thingRegistryClient != null) { thingRegistryClient.Dispose(); thingRegistryClient = null; } if (concentratorServer != null) { concentratorServer.Dispose(); concentratorServer = null; } if (xmppClient != null) { using (ManualResetEvent OfflineSent = new ManualResetEvent(false)) { xmppClient.SetPresence(Availability.Offline, string.Empty, (sender, e) => OfflineSent.Set()); OfflineSent.WaitOne(1000); } foreach (ISniffer Sniffer in xmppClient.Sniffers) { XmppClient.Remove(Sniffer); Disposable = Sniffer as IDisposable; if (Disposable != null) { Disposable.Dispose(); } } xmppClient.Dispose(); xmppClient = null; } if (connectionTimer != null) { connectionTimer.Dispose(); connectionTimer = null; } if (coapEndpoint != null) { coapEndpoint.Dispose(); coapEndpoint = null; } if (webServer != null) { foreach (ISniffer Sniffer in webServer.Sniffers) { webServer.Remove(Sniffer); Disposable = Sniffer as IDisposable; if (Disposable != null) { Disposable.Dispose(); } } webServer.Dispose(); webServer = null; } clientEvents = null; }
public void Dispose() { Disconnect(); Disposable.Dispose(ref Device); }
protected override void EvStateExit() { Disposable.Dispose(); Disposable = null; }