예제 #1
0
        private bool Init()
        {
            try
            {
                if (_CentralManager == null)
                {
                    _CentralManager  = (BluetoothManager)Android.App.Application.Context.GetSystemService(Context.BluetoothService);
                    _ConnectCallback = new BleClientCallback {
                        ConnectionCompleted = ConnectionCompleted
                    };
                    _Devices = new List <BluetoothDevice>();
                }
                _Timeout?.Change(Timeout.Infinite, Timeout.Infinite);
                _IsConnected = false;
                _Semaphore?.Dispose();

                BLE("init OK");
                return(true);
            }
            catch (Exception ex)
            {
                BLE_ERR("init", ex);
                return(false);
            }
        }
예제 #2
0
        internal virtual void Dispose(bool disposing)
        {
            if (!_isDisposed)
            {
#pragma warning disable IDISP007
                ApiClient.Dispose();
#pragma warning restore IDISP007
                _stateLock?.Dispose();
                _isDisposed = true;
            }
        }
예제 #3
0
 public void Dispose()
 {
     if (!(_cancelTokenSource is null))
     {
         _cancelTokenSource.Cancel();
         _cancelTokenSource.Dispose();
         _cleanupTask.GetAwaiter().GetResult();
     }
     _tokenLock?.Dispose();
     _clearToken?.Dispose();
     _requestCancelTokenSource?.Dispose();
 }
예제 #4
0
        public async Task StopReceiver()
        {
            _messageReceiverLoopTokenSource?.Cancel();

            if (_messageReceiverLoop != null && !_messageReceiverLoop.IsFaulted)
            {
                await _messageReceiverLoop;
            }

            await _infrastructureReceiver.StopReceiver();

            _semaphore?.Dispose();
            _messageReceiverLoopTokenSource?.Dispose();
        }
예제 #5
0
 public void Dispose()
 {
     Logger?.LogDebug("Disposing of FtpClient");
     Task.WaitAny(LogOutAsync());
     ControlStream?.Dispose();
     dataSocketSemaphore?.Dispose();
 }
        /// <summary>
        /// Disposes objected used by the class.
        /// </summary>
        /// <param name="disposing">A Boolean that indicates whether the method call comes from a Dispose method (its value is true) or from a finalizer (its value is false).</param>
        /// <remarks>
        /// The disposing parameter should be false when called from a finalizer, and true when called from the IDisposable.Dispose method.
        /// In other words, it is true when deterministically called and false when non-deterministically called.
        /// </remarks>
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Dispose managed objects owned by the class here.
                _cts?.Cancel();

                // Wait for thread to drain
                if (_completionEvent != null && !_completionEvent.WaitOne(_timeoutSeconds * 1000))
                {
                    // TODO:  Flow ILogger to this layer.
                    // AppInsights.TrackEvent("SendQueue.Dispose: _completionEvent timeout!!!", "Timeout Seconds".PairWith(timeoutSeconds));
                }

                _completionEvent?.Dispose();
                _semaphore?.Dispose();
                _cts?.Dispose();
            }

            _disposed = true;
        }
예제 #7
0
        /// <summary>
        /// Releases all Objects held by this socket. Will also
        /// shutdown the socket if its still running
        /// </summary>
        public override void Dispose()
        {
            // No need to do this again
            if (IsDisposed)
            {
                return;
            }
            IsDisposed = true;

            // Shutdown sockets
            Stop();

            // Dispose all AcceptPool AysncEventArg objects
            while (SocketAcceptPool.Count > 0)
            {
                SocketAcceptPool.Pop().Dispose();
            }

            // Dispose all ReadWritePool AysncEventArg objects
            while (SocketReadWritePool.Count > 0)
            {
                SocketReadWritePool.Pop().Dispose();
            }

            // Dispose the buffer manager after disposing all EventArgs
            BufferManager?.Dispose();
            MaxConnectionsEnforcer?.Dispose();
            Listener?.Dispose();
            databaseDriver?.Dispose();
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _mutex?.Dispose();
     }
 }
 public void Dispose()
 {
     circuitBreaker?.Dispose();
     semaphore?.Dispose();
     messageProcessing?.Dispose();
     connection?.Dispose();
 }
예제 #10
0
 public void Dispose()
 {
     _db?.Close();
     _db?.Dispose();
     _writeSemaphore?.Dispose();
     _createSemaphore?.Dispose();
 }
예제 #11
0
 private void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             try
             {
                 Task.WaitAll(pendingTasks.ToArray());
             }
             catch (AggregateException ag)
             {
                 foreach (var e in ag.InnerExceptions)
                 {
                     if (!(e is TaskCanceledException))
                     {
                         throw;
                     }
                 }
             }
             if (pendingTasks != null)
             {
                 foreach (var t in pendingTasks)
                 {
                     t.Dispose();
                 }
             }
             threadLimiter?.Dispose();
         }
         disposed = true;
     }
     pendingTasks  = null;
     threadLimiter = null;
 }
예제 #12
0
        /// <summary>
        /// Releases the unmanaged resources used by the Component and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            try
            {
                if (Logging.IsEnabled)
                {
                    Logging.Enter(this, $"Disposed={_isDisposed}; disposing={disposing}", $"{nameof(AuthenticationWithTokenRefresh)}.{nameof(Dispose)}");
                }

                if (!_isDisposed)
                {
                    if (disposing)
                    {
                        _lock?.Dispose();
                        _lock = null;
                    }

                    _isDisposed = true;
                }
            }
            finally
            {
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, $"Disposed={_isDisposed}; disposing={disposing}", $"{nameof(AuthenticationWithTokenRefresh)}.{nameof(Dispose)}");
                }
            }
        }
예제 #13
0
 /// <summary>
 /// Releases resources.
 /// </summary>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _loadSemaphore?.Dispose();
     }
 }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _signal?.Dispose();
     }
 }
예제 #15
0

        
예제 #16
0
 /// <inheritdoc />
 /// <summary>
 /// 释放
 /// </summary>
 public void Dispose()
 {
     _initLock?.Dispose();
     _versionLock  = null;
     _qqwryDbBytes = null;
     _init         = null;
 }
예제 #17
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                Logging.Enter(this, disposing, nameof(Dispose));

                Cleanup();
                if (!_deviceIdentity.IsPooling())
                {
                    _amqpConnectionHolder?.Dispose();
                }

                _sessionSemaphore?.Dispose();
                _messageReceivingLinkSemaphore?.Dispose();
                _messageReceivingCallbackSemaphore?.Dispose();
                _eventReceivingLinkSemaphore?.Dispose();
                _methodLinkSemaphore?.Dispose();
                _twinLinksSemaphore?.Dispose();

                Logging.Exit(this, disposing, nameof(Dispose));
            }
        }
예제 #18
0
 public void Dispose()
 {
     _takeItemSemaphore.Dispose();
     _addItemSemaphore?.Dispose();
     _takeItemdCts.Dispose();
     _addItemdCts?.Dispose();
 }
예제 #19
0
 public void Dispose()
 {
     _cancelTokenSource?.Dispose();
     _tokenLock?.Dispose();
     _clearToken?.Dispose();
     _requestCancelTokenSource?.Dispose();
 }
예제 #20
0
 public override void Dispose()
 {
     base.Dispose();
     alphaListener.OnNewCursor -= AlphaListener_OnNewCursor;
     semaphore?.Dispose();
     semaphore = null;
 }
예제 #21
0
 public Task Stop()
 {
     _tokenSource.Cancel();
     _tokenRegistration.Dispose();
     _limiter?.Dispose();
     return(_worker);
 }
예제 #22
0
    public void Dispose()
    {
        _completion?.Dispose();
        _readersLock?.Dispose();

        _completion = null;
    }
예제 #23
0
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                Logging.Enter(this, disposing, nameof(Dispose));

                Cleanup();
                if (!_deviceIdentity.IsPooling())
                {
                    _amqpConnectionHolder?.Dispose();
                }

                // For device sas authenticated clients the authentication refresher is associated with the AMQP unit itself,
                // so it needs to be explicitly disposed.
                _amqpAuthenticationRefresher?.StopLoop();
                _amqpAuthenticationRefresher?.Dispose();

                _sessionSemaphore?.Dispose();
                _messageReceivingLinkSemaphore?.Dispose();
                _messageReceivingCallbackSemaphore?.Dispose();
                _eventReceivingLinkSemaphore?.Dispose();
                _methodLinkSemaphore?.Dispose();
                _twinLinksSemaphore?.Dispose();

                Logging.Exit(this, disposing, nameof(Dispose));
            }
        }
예제 #24
0
        private void Dispose(bool disposing)
        {
            try
            {
                if (Logging.IsEnabled)
                {
                    Logging.Enter(this, $"Disposed={_disposed}; disposing={disposing}", $"{nameof(AmqpConnectionHolder)}.{nameof(Dispose)}");
                }

                if (!_disposed)
                {
                    if (disposing)
                    {
                        _amqpIotConnection?.SafeClose();
                        _lock?.Dispose();
                        _amqpIotConnector?.Dispose();
                        lock (_unitsLock)
                        {
                            _amqpUnits.Clear();
                        }
                        _amqpAuthenticationRefresher?.Dispose();
                    }

                    _disposed = true;
                }
            }
            finally
            {
                if (Logging.IsEnabled)
                {
                    Logging.Exit(this, $"Disposed={_disposed}; disposing={disposing}", $"{nameof(AmqpConnectionHolder)}.{nameof(Dispose)}");
                }
            }
        }
 public void Dispose()
 {
     _defaultCapabilitySemaphore?.Dispose();
     _defaultCapabilitySemaphore = null;
     _metadataSemaphore?.Dispose();
     _metadataSemaphore = null;
 }
예제 #26
0
 public void Dispose()
 {
     _messageQueue?.Dispose();
     _subscriptionsSemaphore?.Dispose();
     _connectionCancellationToken?.Dispose();
     _publishingCancellationToken?.Dispose();
 }
예제 #27
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         semaphoreSlim?.Dispose();
     }
 }
예제 #28
0
 public Task Stop()
 {
     _channel.Writer.Complete();
     _tokenSource?.Cancel();
     _limiter?.Dispose();
     return(_worker);
 }
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (Logging.IsEnabled)
            {
                Logging.Info(this, disposing, nameof(Dispose));
            }

            if (disposing)
            {
                _amqpIotConnection?.SafeClose();
                _lock?.Dispose();
                _amqpIotConnector?.Dispose();
                lock (_unitsLock)
                {
                    _amqpUnits.Clear();
                }
                _amqpAuthenticationRefresher?.Dispose();
            }

            _disposed = true;
        }
예제 #30
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         _resetEvent?.Dispose();
     }
 }
        public static void CancelBeforeWait()
        {
            SemaphoreSlim semaphoreSlim = new SemaphoreSlim(2);

            CancellationTokenSource cs = new CancellationTokenSource();
            cs.Cancel();
            CancellationToken ct = cs.Token;

            const int millisec = 100;
            TimeSpan timeSpan = new TimeSpan(100);
            EnsureOperationCanceledExceptionThrown(() => semaphoreSlim.Wait(ct), ct, "CancelBeforeWait:  An OCE should have been thrown.");
            EnsureOperationCanceledExceptionThrown(() => semaphoreSlim.Wait(millisec, ct), ct, "CancelBeforeWait:  An OCE should have been thrown.");
            EnsureOperationCanceledExceptionThrown(() => semaphoreSlim.Wait(timeSpan, ct), ct, "CancelBeforeWait:  An OCE should have been thrown.");
            semaphoreSlim.Dispose();
        }
예제 #32
0
 /// <summary>
 /// Test SemaphoreSlim Dispose
 /// </summary>
 /// <param name="initial">The initial semaphore count</param>
 /// <param name="maximum">The maximum semaphore count</param>
 /// <param name="action">SemaphoreSlim action to be called after Dispose</param>
 /// <param name="exceptionType">The type of the thrown exception in case of invalid cases,
 /// null for valid cases</param>
 /// <returns>True if the test succeeded, false otherwise</returns>
 private static void RunSemaphoreSlimTest4_Dispose(int initial, int maximum, SemaphoreSlimActions? action, Type exceptionType)
 {
     SemaphoreSlim semaphore = new SemaphoreSlim(initial, maximum);
     try
     {
         semaphore.Dispose();
         CallSemaphoreAction(semaphore, action, null);
     }
     catch (Exception ex)
     {
         Assert.NotNull(exceptionType);
         Assert.IsType(exceptionType, ex);
     }
 }
예제 #33
0
        /// <summary>
        /// Call specific SemaphoreSlim method or property
        /// </summary>
        /// <param name="semaphore">The SemaphoreSlim instance</param>
        /// <param name="action">The action name</param>
        /// <param name="param">The action parameter, null if it takes no parameters</param>
        /// <returns>The action return value, null if the action returns void</returns>
        private static object CallSemaphoreAction
            (SemaphoreSlim semaphore, SemaphoreSlimActions? action, object param)
        {
            if (action == SemaphoreSlimActions.Wait)
            {
                if (param is TimeSpan)
                {
                    return semaphore.Wait((TimeSpan)param);
                }
                else if (param is int)
                {
                    return semaphore.Wait((int)param);
                }
                semaphore.Wait();
                return null;
            }
            else if (action == SemaphoreSlimActions.WaitAsync)
            {
                if (param is TimeSpan)
                {
                    return semaphore.WaitAsync((TimeSpan)param).Result;
                }
                else if (param is int)
                {
                    return semaphore.WaitAsync((int)param).Result;
                }
                semaphore.WaitAsync().Wait();
                return null;
            }
            else if (action == SemaphoreSlimActions.Release)
            {
                if (param != null)
                {
                    return semaphore.Release((int)param);
                }
                return semaphore.Release();
            }
            else if (action == SemaphoreSlimActions.Dispose)
            {
                semaphore.Dispose();
                return null;
            }
            else if (action == SemaphoreSlimActions.CurrentCount)
            {
                return semaphore.CurrentCount;
            }
            else if (action == SemaphoreSlimActions.AvailableWaitHandle)
            {
                return semaphore.AvailableWaitHandle;
            }

            return null;
        }
예제 #34
0
        /// <summary>
        /// Test SemaphoreSlim Dispose
        /// </summary>
        /// <param name="initial">The initial semaphore count</param>
        /// <param name="maximum">The maximum semaphore count</param>
        /// <param name="action">SemaphoreSlim action to be called after Dispose</param>
        /// <param name="exceptionType">The type of the thrown exception in case of invalid cases,
        /// null for valid cases</param>
        /// <returns>True if the test succeeded, false otherwise</returns>
        private static void RunSemaphoreSlimTest4_Dispose(int initial, int maximum, SemaphoreSlimActions? action, Type exceptionType)
        {
            Exception exception = null;
            SemaphoreSlim semaphore = new SemaphoreSlim(initial, maximum);
            try
            {
                semaphore.Dispose();
                CallSemaphoreAction(semaphore, action, null);
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            // The code threw excption and it is not expected because the excyptionType param is null
            if (exceptionType == null && exception != null)
            {
                string methodFailed = "RunSemaphoreSlimTest4_Dispose(" + initial + "," + maximum + "," + action + "): FAILED.  ";
                Assert.True(false, string.Format(methodFailed + "Dispose failed, the code threw an exception, and it is not supposed to."));
            }

            // Compare both exception types in case of the code threw exception
            if (exception != null && !Type.Equals(exception.GetType(), exceptionType))
            {
                string methodFailed = "RunSemaphoreSlimTest4_Dispose(" + initial + "," + maximum + "," + action + "): FAILED.  ";
                Assert.True(false, string.Format(methodFailed + "Dispose failed, Excption types do not match"));
            }
        }