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


C# Channel.SubscribeOnProducerThreads方法代码示例

本文整理汇总了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);
 }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:19,代码来源:ChannelTests.cs

示例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));
            }
        }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:27,代码来源:BasicExamples.cs


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