private void Subscriber(CancellationToken token, IObserver <TMessage> observer, ManualResetEventSlim subscribedEvent) { try { using (var socket = new SubscriberSocket()) { socket.Start(_address, _socketType); socket.Subscribe(_topic); subscribedEvent.Set(); while (!token.IsCancellationRequested) { ReceiveMessage(observer, socket); } socket.Unsubscribe(_topic); socket.Stop(_address, _socketType); } } finally { if (!subscribedEvent.IsSet) { subscribedEvent.Set(); } } }