/// <summary> /// Releases unmanaged and - optionally - managed resources /// </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) { DisposableUtility.Dispose(ref _streamResource); } }
protected virtual void Dispose(bool disposing) { if (disposing) { DisposableUtility.Dispose(ref _serialPort); } }
private WaitHandle GetWaitHandle() { // check if needs to be created if (m_waitHandle == null) { // create a new manual reset event with the correct state bool bWasCompleted = IsCompleted; ManualResetEvent mre = new ManualResetEvent(bWasCompleted); if (Interlocked.CompareExchange(ref m_waitHandle, mre, null) != null) { // we lost the race to create the event; dispose the unnecessary one DisposableUtility.Dispose(ref mre); } else { if (!bWasCompleted && IsCompleted) { // if the operation wasn't done when we created the event but is done now, set the event m_waitHandle.Set(); } } } return(m_waitHandle); }
protected virtual void Dispose(bool disposing) { if (disposing) { DisposableUtility.Dispose(ref _udpClient); } }
public void DisposeNonDisposableObject() { object?obj = new object(); DisposableUtility.DisposeObject(ref obj); Assert.IsNull(obj); }
protected virtual void Dispose(bool disposing) { if (disposing) { DisposableUtility.Dispose(ref _networkStream); } }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { DisposableUtility.Dispose(ref _client); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { _masters.IfNotNull(m => m.Values.ForEach(client => DisposableUtility.Dispose(ref client))); } }
public void Dispose() { DisposableClass?d = new DisposableClass(); var dCopy = d; Assert.IsFalse(d.IsDisposed); DisposableUtility.Dispose(ref d); Assert.IsNull(d); Assert.IsTrue(dCopy.IsDisposed); }
public void DisposeDisposableObject() { var d = new DisposableClass(); DisposableClass?d2 = d; DisposableUtility.DisposeObject(ref d2); Assert.IsNull(d2); Assert.IsTrue(d.IsDisposed); }
public void DisposeStruct() { var count = 0; var ds = new DisposableStruct(() => count++); // disposing should invoke the action DisposableUtility.DisposeObject(ref ds); Assert.AreEqual(1, count); // struct should have been replaced with default value, preventing second increment DisposableUtility.DisposeObject(ref ds); Assert.AreEqual(1, count); }
/// <summary> /// Waits for the asynchronous operation to complete, rethrowing any exception that occurred. /// </summary> public void EndInvoke() { // wait for the operation if necessary if (!IsCompleted) { GetWaitHandle().WaitOne(); } // close the wait handle DisposableUtility.Dispose(ref m_waitHandle); // rethrow any exception that occurred during processing if (m_exception != null) { throw m_exception; } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </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) DisposableUtility.Dispose(ref _transport); }