当前位置: 首页>>代码示例>>C#>>正文


C# EventAggregator.SubscribeTo方法代码示例

本文整理汇总了C#中EventAggregator.SubscribeTo方法的典型用法代码示例。如果您正苦于以下问题:C# EventAggregator.SubscribeTo方法的具体用法?C# EventAggregator.SubscribeTo怎么用?C# EventAggregator.SubscribeTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EventAggregator的用法示例。


在下文中一共展示了EventAggregator.SubscribeTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: a_published_message_is_received_by_multiple_subscribers

        public void a_published_message_is_received_by_multiple_subscribers()
        {
            // When the bus publishes a message, it is sent through the socket
            var consumer = new ZeroConsumer<Message>("tcp://localhost:5562");
            var bus = new BusAdapter();
            bus.AttachConsumer(consumer);

            // Meanwhile, the aggregator waits for messages from the same socket
            var producer = new ZeroProducer<Message>("tcp://*:5562");
            var aggregator = new EventAggregator<Message>();
            aggregator.AttachTo(producer);

            // While two test consumers are subscribed to the aggregator
            // (the syntax looks like it's the other way around)
            var confirmById = new FakeEventConsumer();
            var confirmAsReceived = new TestConsumer();
            aggregator.SubscribeTo(confirmById);
            aggregator.SubscribeTo(confirmAsReceived);

            // When we drop a message on the bus, the test consumer should get it
            var @event = new FakeEvent();
            bus.Publish(@event);

            // Pause the thread so the producer (via aggregator) can send to the test consumer
            var timeout = TimeSpan.FromSeconds(1).TotalMilliseconds;
            Thread.Sleep((int)timeout);

            Assert.IsTrue(confirmAsReceived.Received);
            Assert.AreEqual(@event.Id, confirmById.Id);

            producer.Dispose();
            consumer.Dispose();
        }
开发者ID:thefringeninja,项目名称:Event-handling,代码行数:33,代码来源:When_using_bus.cs


注:本文中的EventAggregator.SubscribeTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。