protected override void Dispose(bool disposing) { if (disposing) { _lock.AcquireWriterLock(); try { { while (_outgoingQueue.Count > 0) { RtmpAsyncResult asyncResult = _outgoingQueue.Dequeue() as RtmpAsyncResult; if (asyncResult != null) { asyncResult.SetComplete(new ObjectDisposedException(null)); } } _outgoingQueue.Clear(); } } finally { _lock.ReleaseWriterLock(); } } base.Dispose(disposing); }
private void BeginWriteCallback(IAsyncResult asyncResult) { RtmpAsyncResult asyncState = asyncResult.AsyncState as RtmpAsyncResult; if (asyncState != null) { try { this.InternalEndWrite(asyncResult); _lock.AcquireWriterLock(); try { SetIsWriting(false); } finally { _lock.ReleaseWriterLock(); } asyncState.SetComplete(null); } catch (Exception exception) { _lock.AcquireWriterLock(); try { SetIsWriting(false); } finally { _lock.ReleaseWriterLock(); } asyncState.SetComplete(exception); } finally { try { this.TryBeginWrite(); } catch { } } } }
private void BeginWriteCallback(IAsyncResult asyncResult) { RtmpAsyncResult asyncState = asyncResult.AsyncState as RtmpAsyncResult; if (asyncState != null) { Queue <RtmpAsyncResult> queue; try { this.InternalEndWrite(asyncResult); lock ((queue = this._outgoingQueue)) { this._isWriting = false; } asyncState.SetComplete(null); } catch (Exception exception) { lock ((queue = this._outgoingQueue)) { this._isWriting = false; } asyncState.SetComplete(exception); } finally { try { this.TryBeginWrite(); } catch { } } } }
private void TryBeginWrite() { RtmpAsyncResult asyncResult = null; _lock.AcquireWriterLock(); try { if (this.IsWriting) { return; } if (_outgoingQueue.Count > 0) { asyncResult = _outgoingQueue.Dequeue() as RtmpAsyncResult; SetIsWriting(true); } } finally { _lock.ReleaseWriterLock(); } try { if (asyncResult != null) { this.InternalBeginWrite(asyncResult.Buffer, asyncResult.Offset, asyncResult.Count, new AsyncCallback(this.BeginWriteCallback), asyncResult); } } catch (Exception exception) { _lock.AcquireWriterLock(); try { SetIsWriting(false); } finally { _lock.ReleaseWriterLock(); } if (asyncResult != null) { asyncResult.SetComplete(exception); } throw; } }