當前位置: 首頁>>代碼示例>>C#>>正文


C# TaskCompletionSource.TryCompleteFromEventArgs方法代碼示例

本文整理匯總了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);
     });
 }
開發者ID:Lakerfield,項目名稱:AsyncEx,代碼行數:9,代碼來源:TaskCompletionSourceExtensionsUnitTests.cs

示例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);
     });
 }
開發者ID:Lakerfield,項目名稱:AsyncEx,代碼行數:9,代碼來源:TaskCompletionSourceExtensionsUnitTests.cs

示例3: TryCompleteFromEventArgs_PropagatesResult

 public void TryCompleteFromEventArgs_PropagatesResult()
 {
     AsyncContext.Run(async () =>
     {
         var tcs = new TaskCompletionSource();
         tcs.TryCompleteFromEventArgs(new AsyncCompletedEventArgs(null, false, null));
         await tcs.Task;
     });
 }
開發者ID:Lakerfield,項目名稱:AsyncEx,代碼行數:9,代碼來源:TaskCompletionSourceExtensionsUnitTests.cs

示例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);
     });
 }
開發者ID:Lakerfield,項目名稱:AsyncEx,代碼行數:10,代碼來源:TaskCompletionSourceExtensionsUnitTests.cs

示例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);
     });
 }
開發者ID:Lakerfield,項目名稱:AsyncEx,代碼行數:9,代碼來源:TaskCompletionSourceExtensionsUnitTests.cs

示例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);
     });
 }
開發者ID:Lakerfield,項目名稱:AsyncEx,代碼行數:9,代碼來源:TaskCompletionSourceExtensionsUnitTests.cs


注:本文中的Nito.AsyncEx.TaskCompletionSource.TryCompleteFromEventArgs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。