/// <summary> /// Cancel the subscriber's listening and remove it from the dictionary so that GC can reclaim the resources it occupies /// </summary> public Task RemoveAsync(IMessageSubscriber messageSubscriber) { CheckValue.NotNull(messageSubscriber, nameof(messageSubscriber)); //if no result,return completed directly. if (!_subscriberDic.TryGetValue(messageSubscriber, out _)) { messageSubscriber.Dispose(); return(Task.CompletedTask); } _subscriberDic.TryRemove(messageSubscriber, out _); messageSubscriber.Dispose(); return(Task.CompletedTask); }
static void Main(string[] args) { DefaultColor = Console.ForegroundColor; IMessageSubscriber <SampleEvent> receiver = null; try { IMessagePublisher publisher; LoadSubsystem(out publisher, out receiver); if (publisher == null) { WriteColoredLine("Goodbye", DetailsColor); System.Threading.Thread.Sleep(2000); return; } WriteColoredLine(""); while (PerformAction(publisher, receiver)) { WriteColoredLine(""); } } catch (AggregateException ex) { WriteColoredLine(ex.InnerException.Message, ErrorColor); WriteColoredLine("Press any key to exit"); Console.ReadKey(); } catch (Exception ex) { WriteColoredLine(ex.Message, ErrorColor); WriteColoredLine("Press any key to exit"); Console.ReadKey(); } finally { receiver?.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { _sut.Dispose(); try { // Make a best effort to clear our test queue. _fixture.ClearQueue() .GetAwaiter() .GetResult(); } catch { } } _disposed = true; } }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { // With the RabbitMQ implementation, we must disconnect // our consumer before purging the queue, otherwise, // purging the queue won't remove unacked messages. _sut.Dispose(); try { // Make a best effort to clear our test queue. _fixture.ClearQueue(); } catch { } } _disposed = true; } }
public void Dispose() { _messagePublisher.Dispose(); _messageSubscriber.Dispose(); }