Пример #1
0
        /// <summary>
        /// Disconnects the adapter.
        /// </summary>
        /// <returns></returns>
        public async Task DisconnectAsync()
        {
            if (State == ResonanceComponentState.Connected)
            {
                try
                {
                    Logger.LogInformation("Disconnecting Adapter...");

                    await OnDisconnect();

                    State = ResonanceComponentState.Disconnected;

                    if (WriteMode == ResonanceAdapterWriteMode.Queue)
                    {
                        _pushQueue.BlockEnqueue(null); //Will terminate the push thread.
                    }

                    Logger.LogInformation("Adapter Disconnected...");
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, "Adapter disconnection error occurred.");
                    throw ex;
                }
            }
        }
Пример #2
0
 protected override Task OnDisconnect()
 {
     State = ResonanceComponentState.Disconnected;
     _incomingQueue.BlockEnqueue(null);
     _closeConnection = true;
     return(Task.FromResult(true));
 }
        /// <summary>
        /// Enqueues the specified action.
        /// </summary>
        /// <param name="action">The action.</param>
        public void Enqueue(Action action)
        {
            if (_thread == null)
            {
                _thread = new Thread(DispatchMessages);
                _thread.IsBackground = true;
                _thread.Start();
            }

            _actions.BlockEnqueue(action);
        }
Пример #4
0
 protected override Task OnDisconnect()
 {
     return(Task.Factory.StartNew(() =>
     {
         try
         {
             State = ResonanceComponentState.Disconnected;
             UnregisterRequestHandlers();
             DisposeConnection();
         }
         catch { }
         finally
         {
             _incomingQueue.BlockEnqueue(null);
         }
     }));
 }