public Task StopAsync(CancellationToken cancellationToken) { if (connected) { socket.Unsubscribe(_configuration["EventBus:Topic"]); socket.Disconnect(_configuration["NetMq:SubscribeConnection"]); poller.Stop(); connected = false; } return(Task.CompletedTask); }
/// <summary> /// Stops the proxy, blocking until the underlying <see cref="NetMQPoller"/> has completed. /// </summary> /// <exception cref="InvalidOperationException">The proxy has not been started.</exception> public void Stop() { if (Interlocked.CompareExchange(ref m_state, StateStopping, StateStarted) != StateStarted) { throw new InvalidOperationException("Proxy has not been started"); } if (!m_externalPoller) { m_poller.Stop(); m_poller = null; } m_frontend.ReceiveReady -= OnFrontendReady; m_backend.ReceiveReady -= OnBackendReady; m_state = StateStopped; }
/// <summary> /// Stop the device and safely close the underlying sockets. /// </summary> /// <param name="waitForCloseToComplete">If true, this method will block until the /// underlying poller is fully stopped. Defaults to true.</param> public void Stop(bool waitForCloseToComplete = true) { if (m_pollerIsOwned && m_poller.IsRunning) { if (waitForCloseToComplete) { m_poller.Stop(); } else { m_poller.StopAsync(); } } FrontendSocket.Close(); BackendSocket.Close(); IsRunning = false; }