本文整理匯總了C#中Nito.AsyncEx.TaskCompletionSource.TryCompleteFromEventArgs方法的典型用法代碼示例。如果您正苦於以下問題:C# TaskCompletionSource.TryCompleteFromEventArgs方法的具體用法?C# TaskCompletionSource.TryCompleteFromEventArgs怎麽用?C# TaskCompletionSource.TryCompleteFromEventArgs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nito.AsyncEx.TaskCompletionSource
的用法示例。
在下文中一共展示了TaskCompletionSource.TryCompleteFromEventArgs方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TryCompleteFromEventArgs_PropagatesException
public void TryCompleteFromEventArgs_PropagatesException()
{
AsyncContext.Run(async () =>
{
var tcs = new TaskCompletionSource();
tcs.TryCompleteFromEventArgs(new AsyncCompletedEventArgs(new NotImplementedException(), false, null));
await AssertEx.ThrowsExceptionAsync<NotImplementedException>(() => tcs.Task);
});
}
示例2: TryCompleteFromEventArgs_PropagatesCancellation
public void TryCompleteFromEventArgs_PropagatesCancellation()
{
AsyncContext.Run(async () =>
{
var tcs = new TaskCompletionSource();
tcs.TryCompleteFromEventArgs(new AsyncCompletedEventArgs(null, true, null));
await AssertEx.ThrowsExceptionAsync<OperationCanceledException>(() => tcs.Task);
});
}
示例3: TryCompleteFromEventArgs_PropagatesResult
public void TryCompleteFromEventArgs_PropagatesResult()
{
AsyncContext.Run(async () =>
{
var tcs = new TaskCompletionSource();
tcs.TryCompleteFromEventArgs(new AsyncCompletedEventArgs(null, false, null));
await tcs.Task;
});
}
示例4: TryCompleteFromEventArgsTResult_PropagatesResult
public void TryCompleteFromEventArgsTResult_PropagatesResult()
{
AsyncContext.Run(async () =>
{
var tcs = new TaskCompletionSource<int>();
tcs.TryCompleteFromEventArgs(new AsyncCompletedEventArgs(null, false, null), () => 13);
var result = await tcs.Task;
Assert.AreEqual(13, result);
});
}
示例5: TryCompleteFromEventArgsTResult_PropagatesException
public void TryCompleteFromEventArgsTResult_PropagatesException()
{
Test.Async(async () =>
{
var tcs = new TaskCompletionSource<int>();
tcs.TryCompleteFromEventArgs(new AsyncCompletedEventArgs(new NotImplementedException(), false, null), null);
await AssertEx.ThrowsExceptionAsync<NotImplementedException>(() => tcs.Task);
});
}
示例6: TryCompleteFromEventArgsTResult_PropagatesCancellation
public void TryCompleteFromEventArgsTResult_PropagatesCancellation()
{
Test.Async(async () =>
{
var tcs = new TaskCompletionSource<int>();
tcs.TryCompleteFromEventArgs(new AsyncCompletedEventArgs(null, true, null), null);
await AssertEx.ThrowsExceptionAsync<OperationCanceledException>(() => tcs.Task);
});
}