本文整理汇总了C#中Channel.SubscribeOnProducerThreads方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.SubscribeOnProducerThreads方法的具体用法?C# Channel.SubscribeOnProducerThreads怎么用?C# Channel.SubscribeOnProducerThreads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Channel
的用法示例。
在下文中一共展示了Channel.SubscribeOnProducerThreads方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PubSubFilterTest
public void PubSubFilterTest()
{
Channel<int> channel = new Channel<int>();
SynchronousCommandQueue queue = new SynchronousCommandQueue();
int received = 0;
Action<int> onReceive = delegate(int data)
{
Assert.IsTrue(data%2 == 0);
received++;
};
ChannelSubscription<int> subber = new ChannelSubscription<int>(queue, onReceive);
subber.FilterOnProducerThread = delegate(int msg) { return msg%2 == 0; };
channel.SubscribeOnProducerThreads(subber);
for (int i = 0; i <= 4; i++)
{
channel.Publish(i);
}
Assert.AreEqual(3, received);
}
示例2: PubSubWithDedicatedThreadWithFilter
public void PubSubWithDedicatedThreadWithFilter()
{
using (var fiber = new ThreadFiber())
{
fiber.Start();
var channel = new Channel<int>();
var reset = new AutoResetEvent(false);
Action<int> onMsg = x =>
{
Assert.IsTrue(x % 2 == 0);
if (x == 4)
{
reset.Set();
}
};
var sub = new ChannelSubscription<int>(fiber, onMsg);
sub.FilterOnProducerThread = x => x % 2 == 0;
channel.SubscribeOnProducerThreads(sub);
channel.Publish(1);
channel.Publish(2);
channel.Publish(3);
channel.Publish(4);
Assert.IsTrue(reset.WaitOne(5000, false));
}
}