本文整理汇总了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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例8: DockModule
protected static void DockModule(MessageBus MessageBus, UIModule uiModule, DockState dockState = DockState.Document)
{
MessageBus.SendMessage(new DockRequest(uiModule, dockState) );
}