本文整理汇总了C#中MessageBus.Unsubscribe方法的典型用法代码示例。如果您正苦于以下问题:C# MessageBus.Unsubscribe方法的具体用法?C# MessageBus.Unsubscribe怎么用?C# MessageBus.Unsubscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageBus
的用法示例。
在下文中一共展示了MessageBus.Unsubscribe方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PublishAndUnsubscribe
public void PublishAndUnsubscribe()
{
// Arrange
var bus = new MessageBus();
Action<Object> handler = null;
handler = (m) =>
{
Messages.Add(m);
// Unsubscribe during the publish handler.
bus.Unsubscribe<Object>(handler);
};
bus.Subscribe<Object>(handler);
bus.Subscribe<Object>((m) =>
{
Messages.Add(m);
});
// Act
var message = Guid.NewGuid().ToString();
bus.Publish<Object>(message);
bus.Publish<Object>(message);
// Assert
Assert.AreEqual(3, Messages.Count);
}
示例2: Unsubscribe
public void Unsubscribe()
{
var bus = new MessageBus();
bus.Subscribe<Object>(Handler);
bus.Unsubscribe<Object>(Handler);
var message = new Object();
bus.Publish<Object>(message);
Assert.AreEqual(0, _Messages.Count);
}
示例3: Unsubscribe_MultipleInstances_SameClass
public void Unsubscribe_MultipleInstances_SameClass()
{
// Arrange
var bus = new MessageBus();
// Subscribe two objects of the same type.
var subscriber1 = new TestSubscriber();
bus.Subscribe<Object>(subscriber1.Handler);
var subscriber2 = new TestSubscriber();
bus.Subscribe<Object>(subscriber2.Handler);
// Act
// Unsubscribe the second of the objects and make sure the other first one still gets messages.
bus.Unsubscribe<Object>(subscriber2.Handler);
var message = new Object();
bus.Publish<Object>(message);
// Assert
Assert.AreEqual(0, subscriber2.Messages.Count);
Assert.AreEqual(1, subscriber1.Messages.Count);
}