本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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));
}
}