本文整理汇总了C#中System.Threading.Tasks.Task.TryGetException方法的典型用法代码示例。如果您正苦于以下问题:C# Task.TryGetException方法的具体用法?C# Task.TryGetException怎么用?C# Task.TryGetException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.Task
的用法示例。
在下文中一共展示了Task.TryGetException方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TaskFailedException
public TaskFailedException(string message, Task baseTask)
: base(
String.Format("{0}{1}", message, baseTask != null ? " <-> " + baseTask.TryGetException().Message : String.Empty))
{
}
示例2: AfterSendAsync
/// <summary>
/// After sending, we check if the write was successful or if it was a fire-and-forget.
/// </summary>
/// <param name="sendTask">The task of the send operation.</param>
/// <param name="tcsResponse"></param>
/// <param name="isFireAndForget">True, if we don't expect a response message.</param>
/// <param name="channel"></param>
private async Task AfterSendAsync(Task sendTask, TaskCompletionSource<Message.Message> tcsResponse, bool isFireAndForget, IClientChannel channel)
{
// TODO use for UDP connections, too
await sendTask;
if (sendTask.IsFaulted)
{
string msg = String.Format("Failed to write channel the request {0} {1}.", tcsResponse.Task.AsyncState,
sendTask.Exception);
Logger.Warn(msg);
tcsResponse.SetException(sendTask.TryGetException());
}
if (isFireAndForget)
{
Logger.Debug("Fire and forget message {0} sent. Close channel {1} now. {0}", tcsResponse.Task.AsyncState, channel);
tcsResponse.SetResult(null); // set FF result
// close channel now
}
else
{
//.NET specific, we wait here for the response
// receive response message
// processes client-side inbound pipeline
await channel.ReceiveMessageAsync();
}
channel.Close(); // TODO not needed, receive method closes...
}