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


C# IConnection.ReceiveAsync方法代码示例

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


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

示例1: ProcessMessages

        private Task ProcessMessages(IConnection connection)
        {
            if (_context.Response.IsClientConnected) {
                return connection.ReceiveAsync().ContinueWith(t => {
                    Send(t.Result);
                    return ProcessMessages(connection);
                }).Unwrap();
            }

            if (Disconnected != null) {
                Disconnected();
            }
            return TaskAsyncHelper.Empty;
        }
开发者ID:nyxtom,项目名称:SignalR,代码行数:14,代码来源:ForeverTransport.cs

示例2: ProcessMessages

 private async Task ProcessMessages(IConnection connection)
 {
     long? lastMessageId = null;
     while (!_connectionTokenSource.IsCancellationRequested)
     {
         PersistentResponse response = lastMessageId == null ? await connection.ReceiveAsync() : await connection.ReceiveAsync(lastMessageId.Value);
         lastMessageId = response.MessageId;
         Send(response);
     }
 }
开发者ID:paulbatum,项目名称:SignalR.WebSockets,代码行数:10,代码来源:WebSocketTransport.cs

示例3: ProcessMessages

        private Task ProcessMessages(IConnection connection, long? lastMessageId)
        {
            if (Context.Response.IsClientConnected)
            {
                var responseTask = lastMessageId == null
                    ? connection.ReceiveAsync()
                    : connection.ReceiveAsync(lastMessageId.Value);

                return responseTask.Success(t =>
                {
                    LastMessageId = t.Result.MessageId;
                    Send(t.Result);
                    return ProcessMessages(connection, LastMessageId);
                }).Unwrap();
            }

            // Client is no longer connected
            if (Disconnected != null)
            {
                Disconnected();
            }
            return TaskAsyncHelper.Empty;
        }
开发者ID:robinbetts,项目名称:SignalR,代码行数:23,代码来源:ForeverTransport.cs

示例4: ProcessRequest

        public Func<Task> ProcessRequest(IConnection connection)
        {
            if (IsSendRequest)
            {
                if (Received != null)
                {
                    string data = _context.Request.Form["data"];
                    Received(data);
                }
            }
            else
            {
                if (IsConnectRequest)
                {
                    // Since this is the first request, there's no data we need to retrieve so just wait
                    // on a message to come through
                    _heartBeat.AddConnection(this);
                    if (Connected != null)
                    {
                        Connected();
                    }

                    return () => connection.ReceiveAsync().ContinueWith(t =>
                    {
                        Send(t.Result);
                    });
                }
                else if (MessageId != null)
                {
                    _heartBeat.AddConnection(this);
                    // If there is a message id then we receive with that id, which will either return
                    // immediately if there are already messages since that id, or wait until new
                    // messages come in and then return
                    return () => connection.ReceiveAsync(MessageId.Value).ContinueWith(t =>
                    {
                        // Messages have arrived so let's return
                        Send(t.Result);
                        return TaskAsyncHelper.Empty;
                    }).Unwrap();
                }
            }

            return null;
        }
开发者ID:abuhmead1987,项目名称:Presentations,代码行数:44,代码来源:LongPollingTransport.cs


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