本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}