当前位置: 首页>>代码示例>>C#>>正文


C# TaskCompletionSource.TrySetFromTask方法代码示例

本文整理汇总了C#中TaskCompletionSource.TrySetFromTask方法的典型用法代码示例。如果您正苦于以下问题:C# TaskCompletionSource.TrySetFromTask方法的具体用法?C# TaskCompletionSource.TrySetFromTask怎么用?C# TaskCompletionSource.TrySetFromTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TaskCompletionSource的用法示例。


在下文中一共展示了TaskCompletionSource.TrySetFromTask方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: object

        public void TrySetFromTask_IfSourceTaskIsSuccessfulAndOfDifferentResultType_SucceedsTaskCompletionSourceAndSetsDefaultValueAsResult()
        {
            TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
            Task<object> successfulTask = TaskHelpers.FromResult(new object());

            tcs.TrySetFromTask(successfulTask);

            Assert.Equal(TaskStatus.RanToCompletion, tcs.Task.Status);
            Assert.Equal(null, tcs.Task.Result);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:10,代码来源:TaskHelpersTest.cs

示例2: TrySetFromTask_IfSourceTaskIsSuccessfulAndOfSameResultType_SucceedsTaskCompletionSourceAndSetsResult

        public void TrySetFromTask_IfSourceTaskIsSuccessfulAndOfSameResultType_SucceedsTaskCompletionSourceAndSetsResult()
        {
            TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
            Task<string> successfulTask = TaskHelpers.FromResult("abc");

            tcs.TrySetFromTask(successfulTask);

            Assert.Equal(TaskStatus.RanToCompletion, tcs.Task.Status);
            Assert.Equal("abc", tcs.Task.Result);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:10,代码来源:TaskHelpersTest.cs

示例3: TrySetFromTask_IfSourceTaskIsFaulted_FaultsTaskCompletionSource

        public void TrySetFromTask_IfSourceTaskIsFaulted_FaultsTaskCompletionSource()
        {
            TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
            Exception exception = new Exception();
            Task faultedTask = TaskHelpers.FromError<object>(exception);

            tcs.TrySetFromTask(faultedTask);

            Assert.Equal(TaskStatus.Faulted, tcs.Task.Status);
            Assert.Same(exception, tcs.Task.Exception.InnerException);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:11,代码来源:TaskHelpersTest.cs

示例4: TrySetFromTask_IfSourceTaskIsCanceled_CancelsTaskCompletionSource

        public void TrySetFromTask_IfSourceTaskIsCanceled_CancelsTaskCompletionSource()
        {
            TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
            Task canceledTask = TaskHelpers.Canceled<object>();

            tcs.TrySetFromTask(canceledTask);

            Assert.Equal(TaskStatus.Canceled, tcs.Task.Status);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:9,代码来源:TaskHelpersTest.cs

示例5: TryShowAsync

 public INavigationOperation TryShowAsync(IViewModel viewModel, IDataContext context,
     IViewModelPresenter parentPresenter)
 {
     if (!CanShowViewModel(viewModel, context, parentPresenter))
         return null;
     var tcs = new TaskCompletionSource<object>();
     var operation = new NavigationOperation(tcs.Task);
     context = context.ToNonReadOnly();
     context.AddOrUpdate(NavigationConstants.ViewModel, viewModel);
     var provider = viewModel.GetIocContainer(true).Get<INavigationProvider>();
     provider.CurrentNavigationTask.TryExecuteSynchronously(_ =>
     {
         try
         {
             var task = provider.NavigateAsync(operation.ToOperationCallback(), context);
             tcs.TrySetFromTask(task);
         }
         catch (Exception e)
         {
             tcs.TrySetException(e);
             throw;
         }
     });
     return operation;
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:25,代码来源:DynamicViewModelNavigationPresenter.cs

示例6: Show

 private void Show(IWindowViewMediator viewMediator, INavigationOperation operation, IDataContext context, TaskCompletionSource<object> tcs)
 {
     try
     {
         var task = viewMediator.ShowAsync(operation.ToOperationCallback(), context);
         _currentTask = task;
         tcs.TrySetFromTask(task);
     }
     catch (Exception e)
     {
         tcs.TrySetException(e);
         throw;
     }
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:14,代码来源:DynamicViewModelWindowPresenter.cs


注:本文中的TaskCompletionSource.TrySetFromTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。