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


C# ConnectionManager.GetConnectionContext方法代码示例

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


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

示例1: ConnectionRun

 public ConnectionRun(RunData runData)
     : base(runData)
 {
     var connectionManager = new ConnectionManager(Resolver);
     _context = connectionManager.GetConnectionContext<StressConnection>();
     _transportConnection = (ITransportConnection)_context.Connection;
 }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:7,代码来源:ConnectionRun.cs

示例2: ReceiveLoopRun

        internal static IDisposable ReceiveLoopRun(int connections, int senders, string payload)
        {
            var resolver = new DefaultDependencyResolver();
            var connectionManager = new ConnectionManager(resolver);
            var subscriptions = new List<IDisposable>();
            var senderCountDown = new CountdownEvent(senders);
            var connectionCountDown = new CountdownEvent(connections);
            var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = cancellationTokenSource.Token;
            var context = connectionManager.GetConnectionContext<StressConnection>();

            // Initialize performance counters for this run
            Utility.InitializePerformanceCounters(resolver, cancellationTokenSource.Token);

            for (int i = 0; i < connections; i++)
            {
                var transportConnection = (ITransportConnection)context.Connection;
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    ReceiveLoop(connectionCountDown,
                                transportConnection,
                                messageId: null,
                                cancellationToken: cancellationToken);
                });

            }

            for (var i = 1; i <= senders; i++)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    while (!cancellationTokenSource.IsCancellationRequested)
                    {
                        context.Connection.Broadcast(payload);
                    }

                    senderCountDown.Signal();
                });
            }

            return new DisposableAction(() =>
            {
                cancellationTokenSource.Cancel();

                // Wait for each loop
                connectionCountDown.Wait(TimeSpan.FromMilliseconds(500 * connections));

                // Wait for all senders to stop
                senderCountDown.Wait(TimeSpan.FromMilliseconds(1000 * senders));

                subscriptions.ForEach(s => s.Dispose());
            });
        }
开发者ID:stirno,项目名称:SignalR,代码行数:53,代码来源:ConnectionRun.cs

示例3: RunConnectionTest

        private static void RunConnectionTest()
        {
            string payload = GetPayload();

            var dr = new DefaultDependencyResolver();
            MeasureStats((MessageBus)dr.Resolve<IMessageBus>());
            var connectionManager = new ConnectionManager(dr);
            var context = connectionManager.GetConnectionContext<StressConnection>();

            for (int i = 0; i < _clients; i++)
            {
                ThreadPool.QueueUserWorkItem(state =>
                {
                    Interlocked.Increment(ref _clientsRunning);
                    var transportConnection = (ITransportConnection)context.Connection;
                    transportConnection.Receive(null, r =>
                    {
                        Interlocked.Add(ref _received, r.TotalCount);
                        Interlocked.Add(ref _avgLastReceivedCount, r.TotalCount);
                        return TaskAsyncHelper.True;
                    },
                    maxMessages: 10);

                }, i);
            }

            for (var i = 1; i <= _senders; i++)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    StartSendLoop(i.ToString(), (source, key, value) => context.Connection.Broadcast(value), payload);
                });
            }
        }
开发者ID:neiz,项目名称:SignalR,代码行数:34,代码来源:Program.cs

示例4: RunConnectionReceiveLoopTest

        private static void RunConnectionReceiveLoopTest()
        {
            string payload = GetPayload();

            var dr = new DefaultDependencyResolver();
            MeasureStats((MessageBus)dr.Resolve<IMessageBus>());
            var connectionManager = new ConnectionManager(dr);
            var context = connectionManager.GetConnectionContext<StressConnection>();

            for (int i = 0; i < _clients; i++)
            {
                ThreadPool.QueueUserWorkItem(state =>
                {
                    Interlocked.Increment(ref _clientsRunning);
                    var transportConnection = (ITransportConnection)context.Connection;
                    ReceiveLoop(transportConnection, null);
                }, i);
            }

            for (var i = 1; i <= _senders; i++)
            {
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    StartSendLoop(i.ToString(), (source, key, value) => context.Connection.Broadcast(value), payload);
                });
            }
        }
开发者ID:neiz,项目名称:SignalR,代码行数:27,代码来源:Program.cs


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