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