/// Attempts to complete a <see cref="TaskCompletionSource{TResult}"/>, propagating the completion of <paramref name="task"/> but using the result value from <paramref name="resultFunc"/> if the task completed successfully.
/// </summary>
/// <typeparam name="TResult">The type of the result of the target asynchronous operation.</typeparam>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
/// <param name="task">The task. May not be <c>null</c>.</param>
/// <param name="resultFunc">A delegate that returns the result with which to complete the task completion source, if the task completed successfully. May not be <c>null</c>.</param>
/// <returns><c>true</c> if this method completed the task completion source; <c>false</c> if it was already completed.</returns>
/// Attempts to complete a <see cref="TaskCompletionSource{TResult}"/>, propagating the completion of <paramref name="eventArgs"/>.
/// </summary>
/// <typeparam name="TResult">The type of the result of the asynchronous operation.</typeparam>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
/// <param name="eventArgs">The event arguments passed to the completion event. May not be <c>null</c>.</param>
/// <param name="getResult">The delegate used to retrieve the result. This is only invoked if <paramref name="eventArgs"/> indicates successful completion. May not be <c>null</c>.</param>
/// <returns><c>true</c> if this method completed the task completion source; <c>false</c> if it was already completed.</returns>
/// Attempts to complete a <see cref="TaskCompletionSource{TResult}"/> with the specified value, forcing all continuations onto a threadpool thread even if they specified <c>ExecuteSynchronously</c>.
/// </summary>
/// <typeparam name="TResult">The type of the result of the asynchronous operation.</typeparam>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
/// <param name="result">The result of the asynchronous operation.</param>
// Set the result on a threadpool thread, so any synchronous continuations will execute in the background.
TaskShim.Run(()=>@this.TrySetResult(result));
// Wait for the TCS task to complete; note that the continuations may not be complete.
@this.Task.Wait();
}
/// <summary>
/// Attempts to complete a <see cref="TaskCompletionSource"/>, forcing all continuations onto a threadpool thread even if they specified <c>ExecuteSynchronously</c>.
/// </summary>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
// Set the result on a threadpool thread, so any synchronous continuations will execute in the background.
TaskShim.Run(()=>@this.TrySetResult());
// Wait for the TCS task to complete; note that the continuations may not be complete.
@this.Task.Wait();
}
/// <summary>
/// Attempts to complete a <see cref="TaskCompletionSource{TResult}"/> as canceled, forcing all continuations onto a threadpool thread even if they specified <c>ExecuteSynchronously</c>.
/// </summary>
/// <typeparam name="TResult">The type of the result of the asynchronous operation.</typeparam>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
/// Attempts to complete a <see cref="TaskCompletionSource"/> as canceled, forcing all continuations onto a threadpool thread even if they specified <c>ExecuteSynchronously</c>.
/// </summary>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
// Set the result on a threadpool thread, so any synchronous continuations will execute in the background.
TaskShim.Run(()=>@this.TrySetCanceled());
// Wait for the TCS task to complete; note that the continuations may not be complete.
try
{
@this.Task.Wait();
}
catch(AggregateException)
{
}
}
/// <summary>
/// Attempts to complete a <see cref="TaskCompletionSource{TResult}"/> as faulted, forcing all continuations onto a threadpool thread even if they specified <c>ExecuteSynchronously</c>.
/// </summary>
/// <typeparam name="TResult">The type of the result of the asynchronous operation.</typeparam>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
/// <param name="exception">The exception to bind to the task.</param>
// Wait for the TCS task to complete; note that the continuations may not be complete.
try
{
@this.Task.Wait();
}
catch(AggregateException)
{
}
}
/// <summary>
/// Attempts to complete a <see cref="TaskCompletionSource"/> as faulted, forcing all continuations onto a threadpool thread even if they specified <c>ExecuteSynchronously</c>.
/// </summary>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
/// <param name="exception">The exception to bind to the task.</param>
// Wait for the TCS task to complete; note that the continuations may not be complete.
try
{
@this.Task.Wait();
}
catch(AggregateException)
{
}
}
/// <summary>
/// Attempts to complete a <see cref="TaskCompletionSource{TResult}"/> as faulted, forcing all continuations onto a threadpool thread even if they specified <c>ExecuteSynchronously</c>.
/// </summary>
/// <typeparam name="TResult">The type of the result of the asynchronous operation.</typeparam>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
/// <param name="exceptions">The exceptions to bind to the task.</param>
// Wait for the TCS task to complete; note that the continuations may not be complete.
try
{
@this.Task.Wait();
}
catch(AggregateException)
{
}
}
/// <summary>
/// Attempts to complete a <see cref="TaskCompletionSource"/> as faulted, forcing all continuations onto a threadpool thread even if they specified <c>ExecuteSynchronously</c>.
/// </summary>
/// <param name="this">The task completion source. May not be <c>null</c>.</param>
/// <param name="exceptions">The exceptions to bind to the task.</param>