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


C# MessageBus.SendMessage方法代码示例

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


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

示例1: HeavyLoadTest

        public void HeavyLoadTest()
        {
            const int REPEATER_COUNT = 10;
              const int MESSAGE_COUNT = 200;

              // Arrange
              var bus = new MessageBus();

              var receivers = new MessageRepeater[REPEATER_COUNT];
              for (var i = 0; i < REPEATER_COUNT; i++)
              {
            receivers[i] = new MessageRepeater(bus, i);
            bus.SubscriberFor<RepeatingMessage>(receivers[i].Receive);
              }

              // Act
              var messages = new RepeatingMessage[MESSAGE_COUNT];
              for (var i = 0; i < MESSAGE_COUNT; i++)
              {
            messages[i] = new RepeatingMessage();
            bus.SendMessage(messages[i]);
              }

              // Assert
              var finished = false;
              while (!finished)
              {
            System.Threading.Thread.Sleep(500);
            var count = messages.Count(m => m.Counter == REPEATER_COUNT);
            Console.WriteLine(count);
            if (count == MESSAGE_COUNT)
              finished = true;
              }
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:34,代码来源:MessageBus_CopesWithHeavyLoad.cs

示例2: GCShouldNotKillMessageService

        public void GCShouldNotKillMessageService()
        {
            var bus = new MessageBus();

            bool recieved_message = false;
            var dispose = bus.Listen<int>().Subscribe(x => recieved_message = true);
            bus.SendMessage(1);
            Assert.True(recieved_message);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            recieved_message = false;
            bus.SendMessage(2);
            Assert.True(recieved_message);
        }
开发者ID:jorik041,项目名称:ReactiveUI,代码行数:16,代码来源:MessageBusTest.cs

示例3: SetUp

        public void SetUp()
        {
            bus = new MessageBus();

            var receiverForA = new TestMessageReceiver("receiverForA");
            var receiverForB = new TestMessageReceiver("receiverForB");
            var receiverForAll = new TestMessageReceiver("receiverForAll");

            subscriberA = bus.SubscriberFor<TestMessageTypeA>(receiverForA.Receive);
            subscriberB = bus.SubscriberFor<TestMessageTypeB>(receiverForB.Receive);
            subscriberC = bus.SubscriberFor<TestMessageBase>(receiverForAll.Receive);
            testMessageA = new TestMessageTypeA();
            testMessageB = new TestMessageTypeB();
            testMessageC = new TestMessageTypeC();
            bus.SendMessage(testMessageB);
            bus.SendMessage(testMessageC);

            Thread.Sleep(100);
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:19,代码来源:MessageBusTests.cs

示例4: ExplicitSendMessageShouldWorkEvenAfterRegisteringSource

        public void ExplicitSendMessageShouldWorkEvenAfterRegisteringSource()
        {
            var fixture = new MessageBus();
            fixture.RegisterMessageSource(Observable.Never<int>());

            bool messageReceived = false;
            fixture.Listen<int>().Subscribe(_ => messageReceived = true);

            fixture.SendMessage(42);
            Assert.True(messageReceived);
        }
开发者ID:jorik041,项目名称:ReactiveUI,代码行数:11,代码来源:MessageBusTest.cs

示例5: ListeningBeforeRegisteringASourceShouldWork

        public void ListeningBeforeRegisteringASourceShouldWork()
        {
            var fixture = new MessageBus();
            int result = -1;

            fixture.Listen<int>().Subscribe(x => result = x);

            Assert.Equal(-1, result);

            fixture.SendMessage(42);

            Assert.Equal(42, result);
        }
开发者ID:jorik041,项目名称:ReactiveUI,代码行数:13,代码来源:MessageBusTest.cs

示例6: WhenSubscriberThrowsException

        public void WhenSubscriberThrowsException()
        {
            // Arrange
              var bus = new MessageBus();
              bus.SubscriberFor<Message>(
            m =>
            {
              throw new Exception();
            });
              var exceptions = new Collection<AggregateException>();
              bus.ExceptionListener = exceptions.Add;

              // Act
              bus.SendMessage(new TestMessageTypeA());

              // Assert
              while (exceptions.Count == 0)
              {
            Thread.Sleep(100);
              }
        }
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:21,代码来源:MessageBus_HandlesExceptions.cs

示例7: MessageBusThreadingTest

        public void MessageBusThreadingTest()
        {
            var mb = new MessageBus();
            int? listenedThread = null;
            int? otherThread = null;
            int thisThread = Thread.CurrentThread.ManagedThreadId;

            Task.Run(() => {
                otherThread = Thread.CurrentThread.ManagedThreadId;
                mb.Listen<int>().Subscribe(_ => listenedThread = Thread.CurrentThread.ManagedThreadId);
                mb.SendMessage<int>(42);
            }).Wait();

            Assert.NotEqual(listenedThread.Value, thisThread);
            Assert.Equal(listenedThread.Value, otherThread.Value);
        }
开发者ID:reactiveui,项目名称:ReactiveUI,代码行数:16,代码来源:MessageBusTest.cs

示例8: DockModule

 protected static void DockModule(MessageBus MessageBus, UIModule uiModule, DockState dockState = DockState.Document)
 {
     MessageBus.SendMessage(new DockRequest(uiModule, dockState) );
 }
开发者ID:fremag,项目名称:MemoScope.Net,代码行数:4,代码来源:AbstractUICommand.cs


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