本文整理汇总了C#中TaskCompletionSource.TrySetUnwrappedException方法的典型用法代码示例。如果您正苦于以下问题:C# TaskCompletionSource.TrySetUnwrappedException方法的具体用法?C# TaskCompletionSource.TrySetUnwrappedException怎么用?C# TaskCompletionSource.TrySetUnwrappedException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskCompletionSource
的用法示例。
在下文中一共展示了TaskCompletionSource.TrySetUnwrappedException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WorkImpl
private void WorkImpl(TaskCompletionSource<object> taskCompletionSource)
{
Process:
if (!Alive)
{
// If this subscription is dead then return immediately
taskCompletionSource.TrySetResult(null);
return;
}
var items = new List<ArraySegment<Message>>();
int totalCount;
object state;
PerformWork(items, out totalCount, out state);
if (items.Count > 0)
{
var messageResult = new MessageResult(items, totalCount);
Task<bool> callbackTask = Invoke(messageResult, s => BeforeInvoke(s), state);
if (callbackTask.IsCompleted)
{
try
{
// Make sure exceptions propagate
callbackTask.Wait();
if (callbackTask.Result)
{
// Sync path
goto Process;
}
else
{
// If we're done pumping messages through to this subscription
// then dispose
Dispose();
// If the callback said it's done then stop
taskCompletionSource.TrySetResult(null);
}
}
catch (Exception ex)
{
if (ex.InnerException is TaskCanceledException)
{
taskCompletionSource.TrySetCanceled();
}
else
{
taskCompletionSource.TrySetUnwrappedException(ex);
}
}
}
else
{
WorkImplAsync(callbackTask, taskCompletionSource);
}
}
else
{
taskCompletionSource.TrySetResult(null);
}
}
示例2: WorkImplAsync
private void WorkImplAsync(Task<bool> callbackTask, TaskCompletionSource<object> taskCompletionSource)
{
// Async path
callbackTask.ContinueWith(task =>
{
if (task.IsFaulted)
{
taskCompletionSource.TrySetUnwrappedException(task.Exception);
}
else if (task.IsCanceled)
{
taskCompletionSource.TrySetCanceled();
}
else if (task.Result)
{
WorkImpl(taskCompletionSource);
}
else
{
// If we're done pumping messages through to this subscription
// then dispose
Dispose();
// If the callback said it's done then stop
taskCompletionSource.TrySetResult(null);
}
});
}
示例3: ProcessMessages
private Task ProcessMessages(ITransportConnection connection, Func<Task> postReceive)
{
var tcs = new TaskCompletionSource<object>();
Action<Exception> endRequest = (ex) =>
{
Trace.TraceInformation("DrainWrites(" + ConnectionId + ")");
// Drain the task queue for pending write operations so we don't end the request and then try to write
// to a corrupted request object.
WriteQueue.Drain().Catch().ContinueWith(task =>
{
if (ex != null)
{
tcs.TrySetUnwrappedException(ex);
}
else
{
tcs.TrySetResult(null);
}
CompleteRequest();
Trace.TraceInformation("EndRequest(" + ConnectionId + ")");
},
TaskContinuationOptions.ExecuteSynchronously);
if (AfterRequestEnd != null)
{
AfterRequestEnd();
}
};
ProcessMessages(connection, postReceive, endRequest);
return tcs.Task;
}