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


C# TaskCompletionSource.SetError方法代码示例

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


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

示例1: ContinueInMainThreadWith

		/// <summary>
		/// Creates a continuation that executes on the Main thread when the target <see cref="Task"/> completes.
		/// </summary>
		/// <param name="continuationAction">
		/// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
		/// passed the completed task as an argument.
		/// </param>
		/// <returns>A new continuation <see cref="Task"/>.</returns>
		/// <remarks>
		/// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
		/// completed, whether it completes due to running to completion successfully, faulting due to an
		/// unhandled exception, or exiting out early due to being canceled.
		/// </remarks>
		/// <exception cref="T:System.ArgumentNullException">
		/// The <paramref name="continuationAction"/> argument is null.
		/// </exception>
        public Task ContinueInMainThreadWith(Action<Task> continuationAction)
        {
			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool> ();
			this.Wait ((t) => {
				Dispatcher.instance.ToMainThread(() =>
					{
						try
						{
							continuationAction(t);
							tcs.SetResult(true);
						}
						catch (Exception e)
						{
							tcs.SetError(e);
						}
					});
			});
			return tcs.Task;
        }
开发者ID:XuTenTen,项目名称:MultiThreadComponent,代码行数:35,代码来源:Task.cs

示例2: ConnectToAPI

    IEnumerator ConnectToAPI(int offset, TaskCompletionSource<bool> tcs, Action<int, string> intermediateResult)
    {
        yield return StartCoroutine(YOUR_FAVORITE_API_GetLeaderBoardUsingWWW (offset, queryLimit));

        SortedList<int, string> result = YOUR_FAVORITE_API_GetResultsFromCall ();

        if(result== null)
        {	// mockup an error in the API
            tcs.SetError(new Exception("API returns NULL"));
        }

        foreach(int k in result.Keys)
        {
            intermediateResult(k, result[k]);
        }
        if (result.Count == queryLimit)
        {
            GetCompleteLeaderboardAux(offset + queryLimit, tcs, intermediateResult);
        }
        else
        {
            tcs.SetResult(true);
        }
    }
开发者ID:XuTenTen,项目名称:MultiThreadComponent,代码行数:24,代码来源:LeaderboardTest.cs

示例3: ContinueWith

        /// <summary>
        /// Creates a continuation that executes when the target <see cref="Task"/> completes.
        /// </summary>
        /// <param name="continuationAction">
        /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
        /// passed the completed task as an argument.
        /// </param>
        /// <returns>A new continuation <see cref="Task"/>.</returns>
        /// <remarks>
        /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
        /// completed, whether it completes due to running to completion successfully, faulting due to an
        /// unhandled exception, or exiting out early due to being canceled.
        /// </remarks>
        /// <exception cref="T:System.ArgumentNullException">
        /// The <paramref name="continuationAction"/> argument is null.
        /// </exception>
        public Task ContinueWith(Action<Task> continuationAction)
        {
			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool> ();
			this.Wait ((t) => {
				try
				{
					continuationAction(t);
					tcs.SetResult(true);
				}
				catch (Exception e)
				{
					tcs.SetError(e);
				}
			});
			return tcs.Task;
        }
开发者ID:XuTenTen,项目名称:MultiThreadComponent,代码行数:32,代码来源:Task.cs

示例4: GetCompleteLeaderboardAux

 void GetCompleteLeaderboardAux(int offset, TaskCompletionSource<bool> tcs, Action<int, string> intermediateResult)
 {
     if (m_stopProcessing)
     {
         m_stopProcessing= false;
         tcs.SetError(new Exception("User cancelled"));
     }
     else
     {
         StartCoroutine(ConnectToAPI(offset, tcs, intermediateResult));
     }
 }
开发者ID:XuTenTen,项目名称:MultiThreadComponent,代码行数:12,代码来源:LeaderboardTest.cs


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