// Protected implementation of Dispose pattern. protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { if (cancellationTokenSource != null) { cancellationTokenSource.Cancel(); evt.Set(); receiveMain?.Join(); sendMain?.Join(); statsThread?.Join(); cancellationTokenSource?.Dispose(); } sendUdpClient?.Dispose(); receiveUdpClient?.Dispose(); evt?.Dispose(); } disposed = true; }
private void RunThread() { while (Running) { Active = true; try { action(); } catch (Exception ex) { onException?.Invoke(ex); } finally { Active = false; moreWork.WaitOne(Timeout); } } lock (disposeLock) { moreWork?.Dispose(); } }
void DisposeEvents() { eventClose?.Dispose(); eventActive?.Dispose(); eventFinished?.Dispose(); eventStarted?.Dispose(); }
protected virtual void Dispose(bool disposing) { sleepTimeOut?.Dispose(); sleepTimeOut = null; taskDone?.Dispose(); taskDone = null; }
public void Dispose() { _shouldExit = true; _notifyWrite.Set(); _writeThread.Join(); _notifyWrite?.Dispose(); }
public IRegisteredCallback Create(WaitOrTimerCallback callback, object state) { if (callback == null) { throw new ArgumentNullException(nameof(callback)); } AutoResetEvent waitEvent = null; try { waitEvent = new AutoResetEvent(false); RegisteredWaitHandle waitHandle = null; try { waitHandle = ThreadPool.RegisterWaitForSingleObject(waitEvent, callback, state, Timeout.Infinite, false); return(new RegisteredCallback( waitEvent, waitHandle)); } catch (Exception) { waitHandle?.Unregister(waitEvent); throw; } } catch (Exception) { waitEvent?.Dispose(); throw; } }
public void Dispose() { _sync?.Dispose(); _sync = null; OnAfterEachTest(); }
public void Dispose() { _taskAddedEvent?.Set(); _taskAddedEvent?.Dispose(); _cancellationTokenSource?.Dispose(); _threadConsumer.Join(); }
public void Dispose() { if (_cancelSource == null) { return; } if (AutoReset == null) { return; } if (_running) { _cancelSource.Cancel(); AutoReset?.Set(); while (_running) { Thread.Yield(); } } _cancelSource?.Dispose(); _cancelSource = null; AutoReset?.Dispose(); AutoReset = null; }
private static Task <Bitmap> GetAchievementIconAsync(string achId) { Bitmap result = null; Callback <UserAchievementIconFetched_t> callback = null; AutoResetEvent ev = null; void OnIconFetched(UserAchievementIconFetched_t e) { result = GetBitmapFromHandle(e.m_nIconHandle); // Intentional // ReSharper disable once AccessToModifiedClosure callback?.Dispose(); ev?.Set(); } var iconHandle = SteamUserStats.GetAchievementIcon(achId); if (iconHandle != 0) { result = GetBitmapFromHandle(iconHandle); } else { try { ev = new AutoResetEvent(false); callback = new Callback <UserAchievementIconFetched_t>(OnIconFetched); ev.WaitOne(); } finally { ev?.Dispose(); } } return(Task.FromResult(result)); }
public void Dispose() { Debug.WriteLine("Dispose"); _threadCancel?.Cancel(); _pauseEvent?.Set(); try { Dokan.RemoveMountPoint($"{Letter}:\\"); if (_filesystem != null) { _filesystem.Dispose(); _filesystem = null; } } catch { if (Status != DriveStatus.Unmounted) { Status = DriveStatus.Unmounted; } } finally { _filesystem = null; } _mountCancel?.Dispose(); _threadCancel?.Dispose(); _pauseEvent?.Dispose(); }
protected override void DisposeManagedResources() { _mainThreadLoopAre?.Set(); _mainThreadLoopAre?.Dispose(); _bytesAvailableAre?.Set(); _bytesAvailableAre?.Dispose(); _safeStream?.Dispose(); }
public void Dispose() { _stop = true; _tm?.Dispose(); _tm = null; _autoEvent?.Dispose(); _autoEvent = null; }
private void Dispose(bool disposing) { if (disposing) { _event?.Dispose(); _event = null; } }
protected virtual void Dispose(bool disposing) { if (disposing) { // dispose managed resources _autoResetEvent?.Dispose(); } // free native resources }
public void Dispose() { captchaCts?.Cancel(); captchaCts?.Dispose(); gotGriefed?.Set(); gotGriefed?.Dispose(); mapUpdatedResetEvent?.Set(); mapUpdatedResetEvent?.Dispose(); }
private void Dispose(bool disposing) { ReleaseUnmanagedResources(); if (disposing) { _resetEvent?.Dispose(); _cancellationToken?.Dispose(); } }
protected virtual void Dispose(bool disposing) { ReleaseUnmanagedResources(); if (disposing) { _autoEvent?.Dispose(); _autoEvent?.Close(); } }
public void Dispose() { if (IsRunState(_stateValue)) { Stop(); } _blockEvent?.Dispose(); ExecutionTracker?.Dispose(); }
public void Dispose() { if (!_disposed) { _disposed = true; _autoResetEvent?.Dispose(); _cancellationTokenSource.Dispose(); } }
public void Dispose() { _disposed = true; _end = true; _iterationStart?.Set(); _iterationStart?.Dispose(); _iterationStart = null; }
public void Dispose() { if (!disposed) { eventQueue?.Dispose(); downloadTaskResetEvent?.Dispose(); disposed = true; } }
public void Dispose() { foreach (var cm in _commandManagers) { cm?.Dispose(); } _commandBusEmptyResetEvent?.Dispose(); }
public TestRequest Expect(RequestExpectation expectation) { AutoResetEvent autoResetEvent = null; try { lock (this.lockObj) { // If the request was already made if (this.TryGetMatchingItem(this.outstandingRequests, expectation, out var request)) { return(request); } // The request hasn't been made yet, so create a wait handle to signal when the request does come in autoResetEvent = new AutoResetEvent(false); if (!this.outstandingExpectations.TryGetValue(expectation, out var matchingExpectations)) { matchingExpectations = new Queue <AutoResetEvent>(); this.outstandingExpectations.Add(expectation, matchingExpectations); } matchingExpectations.Enqueue(autoResetEvent); } // Wait for the request to come in for some timeout period. if (!autoResetEvent.WaitOne(this.settings.ExpectationMatchTimeout)) { lock (this.lockObj) { throw new InvalidOperationException($"Expected request was not matched: [{expectation}]. Outstanding requests: [{this.GetOutstandingItemsDebugString(this.outstandingRequests)}]"); } } // It was signalled that the request was made, so try to get the matching request again. It should be there. lock (this.lockObj) { if (this.TryGetMatchingItem(this.outstandingRequests, expectation, out var request)) { return(request); } else { throw new InvalidOperationException( $"A request matching an outstanding expectation was made, but the request could not be found. This is likely a bug. Please report this to the developer. " + $"Expectation: [{expectation}]; " + $"Outstanding expectations: [{this.GetOutstandingItemsDebugString(this.outstandingExpectations)}]; " + $"Outstanding requests: [{this.GetOutstandingItemsDebugString(this.outstandingRequests)}]"); } } } finally { autoResetEvent?.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (disposing) { // dispose managed resources _autoResetEvent?.Dispose(); BIOSEventHandler.DetachDataListener(this); } // free native resources }
//private void HandleConnectionShutdown(Connection connection) { // _connection = null; // Log.Info("Connection Closed"); // OnDisconnected?.Invoke(); // if (State == States.Connected) { // TryConnect(); // } // else if (State == States.ShuttingDown) { // //do nothing, time to saAAAay goodniIIight // } //} //private void HandleIncomingPacket(PacketHeader packetHeader, Connection connection, string incomingObject) { // OnRawMessage?.Invoke(incomingObject); // try { // var t = JsonConvert.DeserializeObject<Msg>(incomingObject); // OnMessage?.Invoke(t); // } // catch (Exception e) { // OnError?.Invoke(e); // } //} public void Dispose() { if (State != States.ShuttingDown) { Shutdown(); } _pingEvent?.Dispose(); _shutdownEvent?.Dispose(); //NetworkComms.Shutdown(); }
private void Dispose(bool disposing) { if (_disposed || !disposing) { return; } _publishLock?.Dispose(); _disposed = true; }
protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _resetEvent?.Dispose(); } _disposedValue = true; } }
protected virtual void Dispose(bool disposing) { _shutdown = true; if (disposing) { // dispose managed resources _autoResetEvent?.Dispose(); _autoResetEvent = null; } // free native resources }
protected override void Dispose(bool disposing) { _shouldRun = false; if (disposing) { _backgroundEvent?.Dispose(); } base.Dispose(disposing); }