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


C# IConnection.SubscribeAsync方法代码示例

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


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

示例1: receiveAsyncSubscriber

        private TimeSpan receiveAsyncSubscriber(IConnection c)
        {
            Stopwatch sw = new Stopwatch();

            using (IAsyncSubscription s = c.SubscribeAsync(subject))
            {
                Object testLock = new Object();

                s.MessageHandler += (sender, args) =>
                {
                    if (received == 0)
                        sw.Start();

                    received++;

                    if (verbose)
                        Console.WriteLine("Received: " + args.Message);

                    replyMsg.Subject = args.Message.Reply;
                    c.Publish(replyMsg);

                    if (received >= count)
                    {
                        sw.Stop();
                        lock (testLock)
                        {
                            Monitor.Pulse(testLock);
                        }
                    }
                };

                lock (testLock)
                {
                    s.Start();
                    Monitor.Wait(testLock);
                }
            }

            return sw.Elapsed;
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:40,代码来源:Replier.cs

示例2: receiveAsyncSubscriber

        private TimeSpan receiveAsyncSubscriber(IConnection c)
        {
            Stopwatch sw = null;
            AutoResetEvent subDone = new AutoResetEvent(false);

            EventHandler<MsgHandlerEventArgs> msgHandler = (sender, args) =>
            {
                if (received == 0)
                {
                    sw = new Stopwatch();
                    sw.Start();
                }

                received++;

                if (verbose)
                    Console.WriteLine("Received: " + args.Message);

                replyMsg.Subject = args.Message.Reply;
                c.Publish(replyMsg);
                c.Flush();

                if (received == count)
                {
                    sw.Stop();
                    subDone.Set();
                }
            };

            using (IAsyncSubscription s = c.SubscribeAsync(subject, msgHandler))
            {
                // just wait to complete
                subDone.WaitOne();
            }

            return sw.Elapsed;
        }
开发者ID:nats-io,项目名称:csnats,代码行数:37,代码来源:Replier.cs

示例3: receiveAsyncSubscriber

        private TimeSpan receiveAsyncSubscriber(IConnection c)
        {
            Stopwatch sw = new Stopwatch();
            Object testLock = new Object();

            EventHandler<MsgHandlerEventArgs> msgHandler = (sender, args) =>
            {
                if (received == 0)
                    sw.Start();

                received++;

                if (verbose)
                    Console.WriteLine("Received: " + args.Message);

                if (received >= count)
                {
                    sw.Stop();
                    lock (testLock)
                    {
                        Monitor.Pulse(testLock);
                    }
                }
            };

            using (IAsyncSubscription s = c.SubscribeAsync(subject, msgHandler))
            {
                // just wait until we are done.
                lock (testLock)
                {
                    Monitor.Wait(testLock);
                }
            }

            return sw.Elapsed;
        }
开发者ID:nats-io,项目名称:csnats,代码行数:36,代码来源:subscribe.cs


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