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


C# ITransportConnection.ReceiveAsync方法代码示例

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


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

示例1: ProcessReceiveRequestWithoutTracking

        private Task ProcessReceiveRequestWithoutTracking(ITransportConnection connection, Action postReceive = null)
        {
            if (TransportConnected != null)
            {
                TransportConnected().Catch();
            }

            // ReceiveAsync() will async wait until a message arrives then return
            var receiveTask = IsConnectRequest ?
                              connection.ReceiveAsync(null, ConnectionEndToken, MessageBufferSize) :
                              connection.ReceiveAsync(MessageId, ConnectionEndToken, MessageBufferSize);

            if (postReceive != null)
            {
                postReceive();
            }

            return receiveTask.Then(response =>
            {
                response.TimedOut = IsTimedOut;

                if (response.Aborted)
                {
                    // If this was a clean disconnect then raise the event
                    OnDisconnect();
                }

                return Send(response);
            });
        }
开发者ID:thoughtentity,项目名称:SignalR,代码行数:30,代码来源:LongPollingTransport.cs

示例2: ReceiveLoop

        private static void ReceiveLoop(ITransportConnection connection, string messageId)
        {
            connection.ReceiveAsync(messageId, CancellationToken.None, maxMessages: 5000).Then(r =>
            {
                Interlocked.Add(ref _received, r.TotalCount);
                Interlocked.Add(ref _avgLastReceivedCount, r.TotalCount);

                ReceiveLoop(connection, r.MessageId);
            });
        }
开发者ID:neiz,项目名称:SignalR,代码行数:10,代码来源:Program.cs

示例3: ProcessMessagesImpl

        private void ProcessMessagesImpl(TaskCompletionSource<object> taskCompletetionSource, ITransportConnection connection, Action postReceive = null)
        {
            if (!IsTimedOut && !IsDisconnected && IsAlive)
            {
                // ResponseTask will either subscribe and wait for a signal then return new messages,
                // or return immediately with messages that were pending
                var receiveAsyncTask = LastMessageId == null
                    ? connection.ReceiveAsync(TimeoutToken)
                    : connection.ReceiveAsync(LastMessageId, TimeoutToken);

                if (postReceive != null)
                {
                    postReceive();
                }

                receiveAsyncTask.Then(response =>
                {
                    LastMessageId = response.MessageId;
                    // If the response has the Disconnect flag, just send the response and exit the loop,
                    // the server thinks connection is gone. Otherwse, send the response then re-enter the loop
                    Task sendTask = Send(response);
                    if (response.Disconnect || response.TimedOut || response.Aborted)
                    {
                        if (response.Aborted)
                        {
                            // If this was a clean disconnect raise the event.
                            OnDisconnect();
                        }

                        // Signal the tcs when the task is done
                        return sendTask.Then(tcs => tcs.SetResult(null), taskCompletetionSource);
                    }

                    // Continue the receive loop
                    return sendTask.Then((conn) => ProcessMessagesImpl(taskCompletetionSource, conn), connection);
                })
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        taskCompletetionSource.SetCanceled();
                    }
                    else if (t.IsFaulted)
                    {
                        taskCompletetionSource.SetException(t.Exception);
                    }
                },
                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnRanToCompletion);

                // Stop execution here
                return;
            }

            taskCompletetionSource.SetResult(null);
            return;
        }
开发者ID:nightbob3,项目名称:SignalR,代码行数:56,代码来源:ForeverTransport.cs

示例4: ProcessReceiveRequestWithoutTracking

        private Task ProcessReceiveRequestWithoutTracking(ITransportConnection connection, Func<Task> postReceive = null)
        {
            if (TransportConnected != null)
            {
                TransportConnected().Catch();
            }

            // ReceiveAsync() will async wait until a message arrives then return
            var receiveTask = IsConnectRequest ?
                              connection.ReceiveAsync(null, ConnectionEndToken, MaxMessages) :
                              connection.ReceiveAsync(MessageId, ConnectionEndToken, MaxMessages);

            return TaskAsyncHelper.Series(() =>
            {
                if (postReceive != null)
                {
                    return postReceive();
                }
                return TaskAsyncHelper.Empty;
            },
            () =>
            {
                return receiveTask.Then(response =>
                {
                    response.TimedOut = IsTimedOut;

                    if (response.Aborted)
                    {
                        // If this was a clean disconnect then raise the event
                        OnDisconnect();
                    }

                    return Send(response);
                });
            });
        }
开发者ID:rustd,项目名称:SignalR,代码行数:36,代码来源:LongPollingTransport.cs

示例5: ProcessReceiveRequest

        private Task ProcessReceiveRequest(ITransportConnection connection, Action postReceive = null)
        {
            HeartBeat.UpdateConnection(this);
            HeartBeat.MarkConnection(this);

            if (TransportConnected != null)
            {
                TransportConnected().Catch();
            }

            // ReceiveAsync() will async wait until a message arrives then return
            var receiveTask = IsConnectRequest ?
                              connection.ReceiveAsync(TimeoutToken) :
                              connection.ReceiveAsync(MessageId, TimeoutToken);

            if (postReceive != null)
            {
                postReceive();
            }

            return receiveTask.Then(response =>
            {
                if (response.Aborted)
                {
                    // If this was a clean disconnect then raise the event
                    OnDisconnect();
                }

                return Send(response);
            });
        }
开发者ID:nightbob3,项目名称:SignalR,代码行数:31,代码来源:LongPollingTransport.cs

示例6: ProcessReceiveRequest

        private Task ProcessReceiveRequest(ITransportConnection connection, Action postReceive = null)
        {
            HeartBeat.MarkConnection(this);

            // ReceiveAsync() will async wait until a message arrives then return
            var receiveTask = IsConnectRequest ?
                              connection.ReceiveAsync(TimeoutToken) :
                              connection.ReceiveAsync(MessageId, TimeoutToken);

            if (postReceive != null)
            {
                postReceive();
            }

            return receiveTask.Then(response => Send(response));
        }
开发者ID:NickBourke,项目名称:SignalR,代码行数:16,代码来源:LongPollingTransport.cs

示例7: ReceiveLoop

        private static void ReceiveLoop(CountdownEvent connectionCountDown, ITransportConnection connection, string messageId, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                connectionCountDown.Signal();
                return;
            }

            connection.ReceiveAsync(messageId, cancellationToken, maxMessages: 5000).Then(r =>
            {
                ReceiveLoop(connectionCountDown, connection, r.MessageId, cancellationToken);
            });
        }
开发者ID:nonintanon,项目名称:SignalR,代码行数:13,代码来源:ConnectionRun.cs


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