// 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();
            }
        }
Exemplo n.º 3
0
 void DisposeEvents()
 {
     eventClose?.Dispose();
     eventActive?.Dispose();
     eventFinished?.Dispose();
     eventStarted?.Dispose();
 }
Exemplo n.º 4
0
 protected virtual void Dispose(bool disposing)
 {
     sleepTimeOut?.Dispose();
     sleepTimeOut = null;
     taskDone?.Dispose();
     taskDone = null;
 }
Exemplo n.º 5
0
 public void Dispose()
 {
     _shouldExit = true;
     _notifyWrite.Set();
     _writeThread.Join();
     _notifyWrite?.Dispose();
 }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        public void Dispose()
        {
            _sync?.Dispose();
            _sync = null;

            OnAfterEachTest();
        }
Exemplo n.º 8
0
 public void Dispose()
 {
     _taskAddedEvent?.Set();
     _taskAddedEvent?.Dispose();
     _cancellationTokenSource?.Dispose();
     _threadConsumer.Join();
 }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 12
0
 protected override void DisposeManagedResources()
 {
     _mainThreadLoopAre?.Set();
     _mainThreadLoopAre?.Dispose();
     _bytesAvailableAre?.Set();
     _bytesAvailableAre?.Dispose();
     _safeStream?.Dispose();
 }
Exemplo n.º 13
0
 public void Dispose()
 {
     _stop = true;
     _tm?.Dispose();
     _tm = null;
     _autoEvent?.Dispose();
     _autoEvent = null;
 }
Exemplo n.º 14
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         _event?.Dispose();
         _event = null;
     }
 }
Exemplo n.º 15
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // dispose managed resources
         _autoResetEvent?.Dispose();
     }
     // free native resources
 }
Exemplo n.º 16
0
 public void Dispose()
 {
     captchaCts?.Cancel();
     captchaCts?.Dispose();
     gotGriefed?.Set();
     gotGriefed?.Dispose();
     mapUpdatedResetEvent?.Set();
     mapUpdatedResetEvent?.Dispose();
 }
Exemplo n.º 17
0
 private void Dispose(bool disposing)
 {
     ReleaseUnmanagedResources();
     if (disposing)
     {
         _resetEvent?.Dispose();
         _cancellationToken?.Dispose();
     }
 }
Exemplo n.º 18
0
 protected virtual void Dispose(bool disposing)
 {
     ReleaseUnmanagedResources();
     if (disposing)
     {
         _autoEvent?.Dispose();
         _autoEvent?.Close();
     }
 }
Exemplo n.º 19
0
 public void Dispose()
 {
     if (IsRunState(_stateValue))
     {
         Stop();
     }
     _blockEvent?.Dispose();
     ExecutionTracker?.Dispose();
 }
Exemplo n.º 20
0
 public void Dispose()
 {
     if (!_disposed)
     {
         _disposed = true;
         _autoResetEvent?.Dispose();
         _cancellationTokenSource.Dispose();
     }
 }
Exemplo n.º 21
0
        public void Dispose()
        {
            _disposed = true;

            _end = true;
            _iterationStart?.Set();
            _iterationStart?.Dispose();
            _iterationStart = null;
        }
Exemplo n.º 22
0
 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
 }
Exemplo n.º 26
0
        //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;
        }
Exemplo n.º 28
0
 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
 }
Exemplo n.º 30
0
        protected override void Dispose(bool disposing)
        {
            _shouldRun = false;

            if (disposing)
            {
                _backgroundEvent?.Dispose();
            }

            base.Dispose(disposing);
        }