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


C# Channel.Subscribe方法代码示例

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


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

示例1: TestTailWithExampleLog

        public void TestTailWithExampleLog()
        {
            File.Delete("test.log");

            var tailfiber = new PoolFiber();
            var reset = new AutoResetEvent(false);

            using (var tail = new Tail())
            {
                var tailchannel = new Channel<string>();
                tailchannel.Subscribe(tailfiber, str =>
                                                     {
                                                         tail.OutputRecievedEvent += OnOutputRecievedEvent;
                                                         tail.Start("test.log");
                                                     });

                tailfiber.Start();

                using (var testlog = new CreateTestLog("test.log"))
                {
                    tailchannel.Publish("");
                    testlog.StartWritingToTestLog(10);
                    testlog.Stop(); //don't really need to call this, but heh, what the...
                }

                tail.Stop();
                while(tail.State != TailState.Stopped){/*wait for tail to stop*/}
            }

            File.Delete("test.log");
        }
开发者ID:andalera,项目名称:TailSentry,代码行数:31,代码来源:TailTestsWithExampleLog.cs

示例2: ShouldCompletelyClearPendingActionsBeforeExecutingNewActions

        public void ShouldCompletelyClearPendingActionsBeforeExecutingNewActions()
        {
            var msgs = new List<int>();

            var sut = new StubFiber { ExecutePendingImmediately = true };
            var channel = new Channel<int>();
            const int count = 4;

            channel.Subscribe(sut, delegate(int x)
                                         {
                                             if (x == count)
                                             {
                                                 return;
                                             }

                                             channel.Publish(x + 1);
                                             msgs.Add(x);
                                         });

            channel.Publish(0);

            Assert.AreEqual(count, msgs.Count);
            for (var i = 0; i < msgs.Count; i++)
            {
                Assert.AreEqual(i, msgs[i]);
            }
        }
开发者ID:rix0rrr,项目名称:SiouxTube,代码行数:27,代码来源:StubFiberTests.cs

示例3: PointToPointPerfTestWithInt

 public void PointToPointPerfTestWithInt()
 {
     var executor = new BoundedQueue(new PerfExecutor()) { MaxDepth = 10000, MaxEnqueueWaitTimeInMs = 1000 };
     using (var fiber = new ThreadFiber(executor))
     {
         fiber.Start();
         var channel = new Channel<int>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         Action<int> onMsg = delegate(int count)
                                 {
                                     if (count == max)
                                     {
                                         reset.Set();
                                     }
                                 };
         channel.Subscribe(fiber, onMsg);
         using (new PerfTimer(max))
         {
             for (var i = 0; i <= max; i++)
             {
                 channel.Publish(i);
             }
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:27,代码来源:PerfTests.cs

示例4: PointToPointPerfTestWithObject

 public void PointToPointPerfTestWithObject(FiberBase fiber)
 {
     using (fiber)
     {
         fiber.Start();
         var channel = new Channel<object>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         var end = new object();
         Action<object> onMsg = delegate(object msg)
         {
             if (msg == end)
                 reset.Set();
         };
         channel.Subscribe(fiber, onMsg);
         Thread.Sleep(100);
         using (new PerfTimer(max))
         {
             var msg = new object();
             for (int i = 0; i <= max; i++)
                 channel.Publish(msg);
             channel.Publish(end);
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
开发者ID:chrisa23,项目名称:Fibrous,代码行数:26,代码来源:PerfTests.cs

示例5: PubSubWithDedicatedThread

        public void PubSubWithDedicatedThread()
        {
            using (var fiber = new ThreadFiber())
            {
                fiber.Start();
                var channel = new Channel<string>();

                var reset = new AutoResetEvent(false);
                channel.Subscribe(fiber, delegate { reset.Set(); });
                channel.Publish("hello");

                Assert.IsTrue(reset.WaitOne(5000, false));
            }
        }
开发者ID:GWBasic,项目名称:retlang,代码行数:14,代码来源:BasicExamples.cs

示例6: TestFromRetlangSitePoolFiber

        public void TestFromRetlangSitePoolFiber()
        {
            //the test from retlang basic example
            using (var fiber = new PoolFiber())
            {
                fiber.Start();
                var channel = new Channel<string>();

                var reset = new AutoResetEvent(false);
                channel.Subscribe(fiber, delegate { reset.Set(); });
                channel.Publish("hello");

                Assert.IsTrue(reset.WaitOne(5000, false));

            }
        }
开发者ID:andalera,项目名称:TailSentry,代码行数:16,代码来源:RetlangTest.cs

示例7: BasicPubSubWithPoolQueue

        public void BasicPubSubWithPoolQueue()
        {
            IFiber queue = new PoolFiber();
            queue.Start();
            Channel<string> hello = new Channel<string>();
            Channel<string> hello2 = new Channel<string>();

            AutoResetEvent reset = new AutoResetEvent(false);
            Action<string> receiveHello = delegate(string str)
                                              {
                                                  Assert.AreEqual("hello", str);
                                                  reset.Set();
                                              };
            hello.Subscribe(queue, receiveHello);
            hello2.Subscribe(queue, receiveHello);
            Assert.IsTrue(hello.Publish("hello"));
            Assert.IsTrue(reset.WaitOne(10000, false));
            queue.Dispose();
        }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:19,代码来源:ChannelTests.cs

示例8: DisposeShouldClearAllLists

        public void DisposeShouldClearAllLists()
        {
            var sut = new StubFiber();
            var channel = new Channel<int>();

            channel.Subscribe(sut, x => { });
            sut.Schedule(() => { }, 1000);
            channel.Publish(2);

            Assert.AreEqual(1, sut.Subscriptions.Count);
            Assert.AreEqual(1, sut.Scheduled.Count);
            Assert.AreEqual(1, sut.Pending.Count);

            sut.Dispose();

            Assert.AreEqual(0, sut.Subscriptions.Count);
            Assert.AreEqual(0, sut.Scheduled.Count);
            Assert.AreEqual(0, sut.Pending.Count);
        }
开发者ID:rix0rrr,项目名称:SiouxTube,代码行数:19,代码来源:StubFiberTests.cs

示例9: Run

        private static void Run(long n, bool useSameThread)
        {
            AutoResetEvent done1 = new AutoResetEvent(false), done2 = new AutoResetEvent(false);

            IQueue q1 = new DefaultQueue(), q2 = new DefaultQueue();
            IFiber f1 = new ThreadFiber(q1), f2 = useSameThread ? f1 : new ThreadFiber(q2);
            IChannel<long> c1 = new Channel<long>(), c2 = new Channel<long>();

            c2.Subscribe(f2, (x) =>
                {
                    if (x < n)
                    {
                        c1.Publish(++x);
                    }
                    if (x >= n)
                    {
                        done2.Set();
                    }
                }
            );

            c1.Subscribe(f1, (x) =>
                {
                    if (x < n)
                    {
                        c2.Publish(++x);
                    }
                    if (x >= n)
                    {
                        done1.Set();
                    }
                }
            );

            f1.Start();
            if (!useSameThread) f2.Start();

            c1.Publish(0);
            EventWaitHandle.WaitAll(new[] { done1, done2 });

            f1.Dispose();
            f2.Dispose();
        }
开发者ID:patrickcooney,项目名称:code,代码行数:43,代码来源:Program.cs

示例10: PointToPointPerfTestWithInt

 public void PointToPointPerfTestWithInt(FiberBase fiber)
 {
     using (fiber)
     {
         fiber.Start();
         var channel = new Channel<int>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         var counter = new CounterInt(reset, max);
         channel.Subscribe(fiber, counter.OnMsg);
         Thread.Sleep(100);
         using (new PerfTimer(max))
         {
             for (int i = 0; i <= max; i++)
                 channel.Publish(i);
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
开发者ID:chrisa23,项目名称:Fibrous,代码行数:19,代码来源:PerfTests.cs

示例11: AsyncRequestReplyWithPrivateChannelUsingThreads

        public void AsyncRequestReplyWithPrivateChannelUsingThreads()
        {
            IFiber responder = new ThreadFiber();
            responder.Start();
            IFiber receiver = new ThreadFiber();
            receiver.Start();

            Channel<Channel<string>> requestChannel = new Channel<Channel<string>>();
            Channel<string> replyChannel = new Channel<string>();
            AutoResetEvent reset = new AutoResetEvent(false);
            Action<Channel<string>> onRequest = delegate(Channel<string> reply) { reply.Publish("hello"); };
            requestChannel.Subscribe(responder, onRequest);
            Action<string> onMsg = delegate(string msg)
                                       {
                                           Assert.AreEqual("hello", msg);
                                           reset.Set();
                                       };
            replyChannel.Subscribe(receiver, onMsg);
            Assert.IsTrue(requestChannel.Publish(replyChannel));
            Assert.IsTrue(reset.WaitOne(10000, false));

            responder.Dispose();
            receiver.Dispose();
        }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:24,代码来源:ChannelTests.cs

示例12: PointToPointPerfTest

 public void PointToPointPerfTest()
 {
     Channel<int> channel = new Channel<int>();
     IFiber bus = new PoolFiber();
     bus.Start();
     int max = 5000000;
     AutoResetEvent reset = new AutoResetEvent(false);
     Action<int> onMsg = delegate(int count)
                             {
                                 if (count == max)
                                 {
                                     reset.Set();
                                 }
                             };
     channel.Subscribe(bus, onMsg);
     using (new PerfTimer(max))
     {
         for (int i = 0; i <= max; i++)
         {
             channel.Publish(i);
         }
         Assert.IsTrue(reset.WaitOne(30000, false));
     }
 }
开发者ID:huangyingwen,项目名称:retlang-1,代码行数:24,代码来源:ChannelTests.cs

示例13: RunBoundedQueue

 private static void RunBoundedQueue()
 {
     var executor = new BoundedQueue(new PerfExecutor()) { MaxDepth = 10000, MaxEnqueueWaitTimeInMs = 1000 };
     using (var fiber = new ThreadFiber(executor))
     {
         fiber.Start();
         var channel = new Channel<MessageStruct>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         Action<MessageStruct> onMessage = delegate(MessageStruct count)
         {
             if (count.count == max)
             {
                 reset.Set();
             }
         };
         channel.Subscribe(fiber, onMessage);
         using (new PerfTimer(max))
         {
             for (var i = 0; i <= max; i++)
             {
                 channel.Publish(new MessageStruct { count = i });
             }
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
开发者ID:GWBasic,项目名称:retlang,代码行数:27,代码来源:PerfTests.cs

示例14: TestLongRunningConceptWithRetlang

        public void TestLongRunningConceptWithRetlang()
        {
            var longrunningContext = new PoolFiber();
            longrunningContext.Start();
            var regularContext = new PoolFiber();
            regularContext.Start();

            var startFollowingFileChannel = new Channel<StartFollowingFileMessage>();
            var stopFollowingFileChannel = new Channel<StopFollowingFileMessage>();
            var followerStartedChannel = new Channel<FollowerStartedMessage>();
            var followerStoppedChannel = new Channel<FollowerStoppedMessage>();
            var longrunningTest = new LongRunningTest(followerStartedChannel, followerStoppedChannel);

            //this one runs in it's own context cause it won't end until a flag is set.
            startFollowingFileChannel.Subscribe(longrunningContext, longrunningTest.Handle);
            //this is registered on another context because if it's on the longrunning one, it won't ever run.
            stopFollowingFileChannel.Subscribe(regularContext, longrunningTest.Handle);

            var reset = new AutoResetEvent(false);
            Guid identifier;

            followerStartedChannel.Subscribe(regularContext, message =>
                                                                 {
                                                                     Console.WriteLine("Follower Started" + message.Identifier);
                                                                     identifier = message.Identifier;
                                                                     stopFollowingFileChannel.Publish(new StopFollowingFileMessage(identifier));
                                                                 });
            followerStoppedChannel.Subscribe(regularContext, message =>
                                                                 {
                                                                     Console.WriteLine("Follower stopped" + message.Identifier);
                                                                     reset.Set();
                                                                 });

            startFollowingFileChannel.Publish(new StartFollowingFileMessage(@"ExampleFiles/ExampleLogFiles/LotroLog.txt"));

            Assert.IsTrue(reset.WaitOne(5000, false));
        }
开发者ID:andalera,项目名称:TailSentry,代码行数:37,代码来源:FileFollowerTests.cs

示例15: PointToPointPerfTestWithObject

 public void PointToPointPerfTestWithObject()
 {
     var executor = new BoundedQueue(new PerfExecutor()) { MaxDepth = 100000, MaxEnqueueWaitTimeInMs = 1000 };
     using (var fiber = new ThreadFiber(executor))
     {
         fiber.Start();
         var channel = new Channel<object>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         var end = new object();
         Action<object> onMessage = delegate(object message)
                                    {
                                        if (message == end)
                                        {
                                            reset.Set();
                                        }
                                    };
         channel.Subscribe(fiber, onMessage);
         using (new PerfTimer(max))
         {
             var message = new object();
             for (var i = 0; i <= max; i++)
             {
                 channel.Publish(message);
             }
             channel.Publish(end);
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
开发者ID:GWBasic,项目名称:retlang,代码行数:30,代码来源:PerfTests.cs


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