Ejemplo n.º 1
0
        public override void Dispose()
        {
            lockResetEvent?.Close();
            connectionResetEvent?.Close();

            base.Dispose();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Stop serial handler
 /// </summary>
 /// <returns></returns>
 public bool Stop()
 {
     _runingEvent?.Reset();
     if (_thrdRead != null && _thrdRead.IsAlive)
     {
         _thrdRead.Join();
         _thrdRead = null;
     }
     if (_thrdHandle != null && _thrdRead.IsAlive)
     {
         _thrdHandle.Join();
         _thrdHandle = null;
     }
     if (this._serialPort != null && this._serialPort.IsOpen)
     {
         this._serialPort.Close();
     }
     _cmdResponseReset?.Close();
     _cmdResponseReset = null;
     _runingEvent?.Close();
     _runingEvent = null;
     _quCmdRespone?.Clear();
     _quCmdRespone = null;
     _quReceiveBuff?.Clear();
     _quReceiveBuff = null;
     return(true);
 }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // dispose managed resources
         _autoResetEvent?.Close();
     }
     // free native resources
 }
Ejemplo n.º 4
0
 protected virtual void Dispose(bool disposing)
 {
     ReleaseUnmanagedResources();
     if (disposing)
     {
         _autoEvent?.Dispose();
         _autoEvent?.Close();
     }
 }
Ejemplo n.º 5
0
 public void Clear()
 {
     Socket?.Close();
     Unpacker?.Clear();
     _autoResetEvent?.Close();
     ReadArgs  = null;
     WriteArgs = null;
     Socket    = null;
 }
Ejemplo n.º 6
0
        public void Dispose()
        {
            #if NETSTANDARD2_0
            _sendCompleted?.Dispose();
            #endif
            #if NETFX
            _sendCompleted?.Close();
            _sendThread?.Abort();
            _sendThread = null;
            #endif

            _sendCompleted = null;
        }
Ejemplo n.º 7
0
        public void CleanupForTimeOutSpecs()
        {
            if (_debugWriterSubscriptionService != null)
            {
                _debugWriterSubscriptionService.Unsubscribe();
                _debugWriterSubscriptionService.Dispose();
            }
            _resetEvt?.Close();
            var environmentModel = _scenarioContext.Get <IServer>("server");
            var resourceModel    = _scenarioContext.Get <ResourceModel>("resourceModel");

            environmentModel?.ResourceRepository?.DeleteResource(resourceModel);
        }
Ejemplo n.º 8
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                eventObject?.WaitOne();
                eventObject?.Close();
                eventObject = null;

                wasapi.Dispose();
                captureClient.Dispose();
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 9
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                eventObject?.WaitOne();
                eventObject?.Close();
                eventObject = null;

                wasapi.Dispose();
                renderClient.Dispose();
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (disposing)
            {
                Cache?.Dispose();
                _cacheLock?.Close();
            }

            _isDisposed = true;
        }
Ejemplo n.º 11
0
 void CommandsManager_CommandWorker()
 {
     try
     {
         while (true)
         {
             if (CommandQueue.Count == 0)
             {
                 CommandQueued.WaitOne();
             }
             KeyValuePair <string, ThreadStart> todo;
             lock (CommandQueue)
             {
                 if (CommandQueue.Count == 0)
                 {
                     continue;
                 }
                 todo = CommandQueue.Dequeue();
             }
             try
             {
                 todo.Value();
             }
             catch (ThreadAbortException)
             {
                 break;
             }
             catch (Exception ex)
             {
                 instance.TabConsole.DisplayNotificationInChat(
                     string.Format("Command error: {0} \n{1} {2} ", todo.Key, ex.Message, ex.StackTrace));
             }
         }
     }
     finally
     {
         CommandQueue.Clear();
         try
         {
             CommandQueued?.Close();
         }
         catch (Exception)
         {
         }
     }
 }
Ejemplo n.º 12
0
        protected virtual void Dispose(bool disposing)
        {
            Debug.WriteLine("DISPOSE");
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _mediaPlayer?.Dispose();
                _libVLC?.Dispose();
                _imageData?.Free();
                _stopped?.Close();
            }

            // Free any unmanaged objects here.
            //
            _disposed = true;
        }
Ejemplo n.º 13
0
        void DoWatch(object parameter)
        {
            AutoResetEvent exitEvent = (AutoResetEvent)parameter;

            try
            {
                using (GroupPolicyNotificationRegistration registration = registrationBuilder.CreateRegistration())
                {
                    AutoResetEvent[] policyEvents
                        = new AutoResetEvent[] { exitEvent, registration.MachinePolicyEvent, registration.UserPolicyEvent };

                    bool listening = true;

                    while (listening)
                    {
                        int result = WaitHandle.WaitAny(policyEvents); // 0 == exit, 1 == machine, 2 == user
                        if (result != 0)
                        {
                            // notification from policy handles, not from exit
                            // fire the change notification mechanism
                            if (GroupPolicyUpdated != null)
                            {
                                GroupPolicyUpdated(result == 1);
                            }
                        }
                        else
                        {
                            // notification from exit
                            listening = false;
                        }
                    }
                }
            }
            finally
            {
                // release the thread's exit event.
                exitEvent.Close();
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose()
        {
            object exit = Interlocked.Exchange(ref _sync, null);

            if (_event != null)
            {
                _event.Close();
            }

            if (exit == null)
            {
                return;
            }

            using (new SafeLock <InvalidOperationException>(exit, 0))
            {
                if (_readersCount > 0)
                {
                    throw new InvalidOperationException();
                }
            }
        }
Ejemplo n.º 15
0
        protected override void DoWaitForCompleteStop()
        {
            s_Servers.Unregister(this);

            if (m_AcceptThread != null)
            {
                m_AcceptThread.Join();
                m_AcceptThread = null;
            }

            if (m_InstrumentationThread != null)
            {
                m_InstrumentationThread.Join();
                m_InstrumentationThread = null;
                m_InstrumentationThreadWaiter.Close();
            }

            closeListener();

            try
            {
                m_Dispatcher.WaitForCompleteStop();
                if (m_Gate != null)
                {
                    if (m_Gate is Service)
                    {
                        ((Service)m_Gate).WaitForCompleteStop();
                    }
                }
            }
            finally
            {
                m_AcceptSemaphore.Dispose();
                m_AcceptSemaphore = null;

                m_WorkSemaphore.Dispose();
                m_WorkSemaphore = null;
            }
        }
Ejemplo n.º 16
0
        private void Free( )
        {
            if (imageProcessingThread != null)
            {
                nestedVideoSource.NewFrame -= new NewFrameEventHandler(nestedVideoSource_NewFrame);

                // make sure processing thread does nothing
                isProcessingThreadAvailable.WaitOne( );
                // signal worker thread to stop and wait for it
                lastVideoFrame = null;
                isNewFrameAvailable.Set( );
                imageProcessingThread.Join( );
                imageProcessingThread = null;

                // release events
                isNewFrameAvailable.Close( );
                isNewFrameAvailable = null;

                isProcessingThreadAvailable.Close( );
                isProcessingThreadAvailable = null;
            }
        }
Ejemplo n.º 17
0
 public bool HandleKey(Atk.KeyEventStruct evnt)
 {
     if (KeyListenerList.Count == 0)
     {
         return(false);
     }
     foreach (KeyValuePair <uint, KeyListenerInfo> kvp in KeyListenerList)
     {
         int            result = 0;
         AutoResetEvent sync   = GLibHacks.Invoke(delegate(object sender, EventArgs args) {
             result = kvp.Value.listener(evnt);
         });
         sync.WaitOne();
         sync.Close();
         sync = null;
         if (result != 0)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 18
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (autoEvent != null)
                    {
                        timer.Stop();
                        autoEvent.WaitOne();

                        timer.Dispose();
                        timer = null;

                        autoEvent.Close();
                        autoEvent = null;
                    }
                }

                disposed = true;
            }
        }
Ejemplo n.º 19
0
        private void _BufferPopulationThread()
        {
            IsRunning = true;

            IEnumerator <IEffectNode> dataEnumerator = EffectNodeSource.GetEnumerator();

            try {
                while (IsRunning)
                {
                    while (_IsBufferInadequate() && IsRunning && dataEnumerator.MoveNext())
                    {
                        _AddToQueue(dataEnumerator.Current);
                    }

                    _bufferReadSignal.WaitOne();
                }
            } finally {
                dataEnumerator.Dispose();
                _bufferReadSignal.Close();
                _bufferReadSignal.Dispose();
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Closes the broker.  All pending <see cref="Dequeue" />
        /// calls will return <c>null</c>.
        /// </summary>
        public void Close()
        {
            lock (syncLock)
            {
                if (!isOpen)
                {
                    return;
                }

                queue  = null;
                isOpen = false;

                if (cDequeue == 0)
                {
                    wait.Close();
                }
                else
                {
                    wait.Set();
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            lock (this)
            {
                if (!Disposed)
                {
                    Disposed = true;
                    GC.SuppressFinalize(this);

                    _onDelayEventEndHandler = null;
                    Stop();

                    _autoEventBegin?.Close();
                    _autoEventBegin?.Dispose();
                    _autoEventBegin = null;

                    _autoEventEnd?.Close();
                    _autoEventEnd?.Dispose();
                    _autoEventEnd = null;
                }
            }
        }
Ejemplo n.º 22
0
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            HTTPManager.Logger.Information("UploadStream", string.Format("{0} - Dispose", this.Name));

            ReadBuffer.Dispose();
            ReadBuffer = null;

            WriteBuffer.Dispose();
            WriteBuffer = null;

#if NETFX_CORE
            ARE.Dispose();
#else
            ARE.Close();
#endif
            ARE = null;
        }

        base.Dispose(disposing);
    }
Ejemplo n.º 23
0
 /** Atomically interact with the RE, return true if it was closed BEFORE
  * @param set if true, try to Set the RE
  * @param close if true, try to Close the RE
  * @return true if the RE was already closed.
  * both arguments should not be true
  */
 private bool SetOrCloseRE(bool set, bool close)
 {
     lock ( _re_sync ) {
         if (_re == null)
         {
             return(true);
         }
         //Looks like we can actually try to work now:
         if (set)
         {
             //This is the more common case, so put it first
             _re.Set();
         }
         else if (close)
         {
             _re.Close();
             _re = null;
         }
     }
     //If we got here, it wasn't already closed
     return(false);
 }
Ejemplo n.º 24
0
 public void Dispose()
 {
     try
     {
         if (m_Header.lpData != IntPtr.Zero)
         {
             WaveNative.waveInUnprepareHeader(m_WaveIn, ref m_Header, Marshal.SizeOf(m_Header));
             m_HeaderHandle.Free();
             m_Header.lpData = IntPtr.Zero;
         }
         m_RecordEvent.Close();
         if (m_HeaderDataHandle.IsAllocated)
         {
             m_HeaderDataHandle.Free();
         }
         GC.SuppressFinalize(this);
     }
     catch (Exception ex)
     {
         LogManage.WriteLog(this.GetType(), ex);
     }
 }
Ejemplo n.º 25
0
        public void Kill()
        {
            //Kill is called on client thread - must use cached thread object
            Debug.Assert(m_ThreadObj != null);
            if (m_ThreadObj.IsAlive == false)
            {
                return;
            }
            EndLoop = true;
            m_ItemAdded.Set();

            //Wait for thread to die
            m_ThreadObj.Join();
            if (m_EndLoopMutex != null)
            {
                m_EndLoopMutex.Close();
            }
            if (m_ItemAdded != null)
            {
                m_ItemAdded.Close();
            }
        }
Ejemplo n.º 26
0
        public void Dispose(WebSocketCloseStatus status, string errorMessage)
        {
            if (disposedFlag.Set())
            {
                switch (webSocket.State)
                {
                case WebSocketState.Connecting:
                case WebSocketState.Open:
                case WebSocketState.CloseReceived:
                    MiscHelpers.Try(() => webSocket.CloseOutputAsync(status, errorMessage, CancellationToken.None));
                    break;
                }

                var tempQueueWaitHandle = queueWaitHandle;
                if (tempQueueWaitHandle != null)
                {
                    tempQueueWaitHandle.Unregister(null);
                }

                queueEvent.Close();
            }
        }
Ejemplo n.º 27
0
        public static TimedRunnerResult <TR> RunWithTimeout <TR>(Func <TR> proc, TimeSpan timeout)
        {
            using (var waitHandle = new AutoResetEvent(false))
            {
                var ret    = default(TR);
                var thread = new Thread(() =>
                {
                    ret = proc();
                    waitHandle.Set();
                })
                {
                    IsBackground = true
                };
                thread.Start();

                var timedOut = !waitHandle.WaitOne(timeout, false);
                waitHandle.Close();

                if (timedOut)
                {
                    try
                    {
                        thread.Abort();
                    }
                    catch { }
                    return(new TimedRunnerResult <TR>
                    {
                        Result = default(TR),
                        IsTimedOut = true
                    });
                }

                return(new TimedRunnerResult <TR>
                {
                    Result = ret,
                    IsTimedOut = false
                });
            }
        }
        public void NotifyAsync_ShouldSetRequestStatusToSuccessOnlyIfStatusCodeCreated(bool isStatusCodeCreated)
        {
            var config = new AirbrakeConfig
            {
                ProjectId  = "127348",
                ProjectKey = "e2046ca6e4e9214b24ad252e3c99a0f6"
            };

            using (var requestHandler = new FakeHttpRequestHandler())
            {
                requestHandler.HttpResponse.StatusCode = isStatusCodeCreated
                    ? HttpStatusCode.Created
                    : HttpStatusCode.BadRequest;
                requestHandler.HttpResponse.ResponseJson = "{\"Id\":\"12345\",\"Url\":\"https://airbrake.io/\"}";

                var notifier   = new AirbrakeNotifier(config, new FakeLogger(), requestHandler);
                var resetEvent = new AutoResetEvent(false);
                AirbrakeResponse airbrakeResponse = null;
                notifier.NotifyCompleted += (sender, eventArgs) =>
                {
                    airbrakeResponse = eventArgs.Result;
                    resetEvent.Set();
                };

                notifier.NotifyAsync(new Exception());

                Assert.Equal(resetEvent.WaitOne(2000), true);
                resetEvent.Close();

                if (isStatusCodeCreated)
                {
                    Assert.True(airbrakeResponse.Status == RequestStatus.Success);
                }
                else
                {
                    Assert.True(airbrakeResponse.Status == RequestStatus.RequestError);
                }
            }
        }
Ejemplo n.º 29
0
            /// <summary>准备好定时器列表</summary>
            /// <returns></returns>
            static TimerX[] Prepare()
            {
                if (timers == null || timers.Count < 1)
                {
                    // 没有计时器,设置一个较大的休眠时间
                    //period = 60000;

                    // 使用事件量来控制线程
                    if (waitForTimer != null)
                    {
                        waitForTimer.Close();
                    }

                    waitForTimer = new AutoResetEvent(false);
                    waitForTimer.WaitOne(Timeout.Infinite, false);
                }

                lock (timers)
                {
                    return(timers.ToArray());
                }
            }
Ejemplo n.º 30
0
        public void Dispose()
        {
            try
            {
                Close();
            }
            catch { }
            if (!IsDisposed())
            {
                Marshal.ReleaseComObject(m_pReader);
                m_pReader     = null;
                m_pHeaderInfo = null;
            }

            if (IntPtr.Zero != m_hWaveOut)
            {
                waveOut.Close(m_hWaveOut); // Ignore return
                m_hWaveOut = IntPtr.Zero;
            }

            if (IntPtr.Zero != m_hMixer)
            {
                Mixer.Close(m_hMixer);
                m_hMixer = IntPtr.Zero;
            }

            if (null != m_hAsyncEvent)
            {
                m_hAsyncEvent.Close();
                m_hAsyncEvent = null;
            }

            m_pWfx = null;
#if SUPPORT_DRM
            objDRM.Dispose();
            m_pwszURL = null;
#endif
        }