TplExtensions.NoThrowAwaitable Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
NoThrowAwaitable(Task, Boolean) |
Returns an awaitable for the specified task that will never throw, even if the source task faults or is canceled. |
NoThrowAwaitable(ValueTask, Boolean) |
Returns an awaitable for the specified task that will never throw, even if the source task faults or is canceled. |
NoThrowAwaitable<TResult>(ValueTask<TResult>, Boolean) |
Returns an awaitable for the specified task that will never throw, even if the source task faults or is canceled. |
NoThrowAwaitable(Task, Boolean)
Returns an awaitable for the specified task that will never throw, even if the source task faults or is canceled.
public static Microsoft.VisualStudio.Threading.TplExtensions.NoThrowTaskAwaitable NoThrowAwaitable (this System.Threading.Tasks.Task task, bool captureContext = true);
static member NoThrowAwaitable : System.Threading.Tasks.Task * bool -> Microsoft.VisualStudio.Threading.TplExtensions.NoThrowTaskAwaitable
<Extension()>
Public Function NoThrowAwaitable (task As Task, Optional captureContext As Boolean = true) As TplExtensions.NoThrowTaskAwaitable
Parameters
- task
- Task
The task whose completion should signal the completion of the returned awaitable.
- captureContext
- Boolean
if set to true
the continuation will be scheduled on the caller's context; false
to always execute the continuation on the threadpool.
Returns
An awaitable.
Applies to
NoThrowAwaitable(ValueTask, Boolean)
Returns an awaitable for the specified task that will never throw, even if the source task faults or is canceled.
public static Microsoft.VisualStudio.Threading.TplExtensions.NoThrowValueTaskAwaitable NoThrowAwaitable (this System.Threading.Tasks.ValueTask task, bool captureContext = true);
static member NoThrowAwaitable : System.Threading.Tasks.ValueTask * bool -> Microsoft.VisualStudio.Threading.TplExtensions.NoThrowValueTaskAwaitable
<Extension()>
Public Function NoThrowAwaitable (task As ValueTask, Optional captureContext As Boolean = true) As TplExtensions.NoThrowValueTaskAwaitable
Parameters
- task
- ValueTask
The task whose completion should signal the completion of the returned awaitable.
- captureContext
- Boolean
if set to true
the continuation will be scheduled on the caller's context; false
to always execute the continuation on the threadpool.
Returns
An awaitable.
Applies to
NoThrowAwaitable<TResult>(ValueTask<TResult>, Boolean)
Returns an awaitable for the specified task that will never throw, even if the source task faults or is canceled.
public static Microsoft.VisualStudio.Threading.TplExtensions.NoThrowValueTaskAwaitable<TResult> NoThrowAwaitable<TResult> (this System.Threading.Tasks.ValueTask<TResult> task, bool captureContext = true);
static member NoThrowAwaitable : System.Threading.Tasks.ValueTask<'Result> * bool -> Microsoft.VisualStudio.Threading.TplExtensions.NoThrowValueTaskAwaitable<'Result>
<Extension()>
Public Function NoThrowAwaitable(Of TResult) (task As ValueTask(Of TResult), Optional captureContext As Boolean = true) As TplExtensions.NoThrowValueTaskAwaitable(Of TResult)
Type Parameters
- TResult
The type of the result.
Parameters
- task
- ValueTask<TResult>
The task whose completion should signal the completion of the returned awaitable.
- captureContext
- Boolean
if set to true
the continuation will be scheduled on the caller's context; false
to always execute the continuation on the threadpool.
Returns
An awaitable.
Remarks
The awaitable returned by this method does not provide access to the result of a successfully-completed ValueTask<TResult>. To await without throwing and use the resulting value, the following pattern may be used:
var methodValueTask = MethodAsync().Preserve();
await methodValueTask.NoThrowAwaitable(true);
if (methodValueTask.IsCompletedSuccessfully)
{
var result = methodValueTask.Result;
}
else
{
var exception = methodValueTask.AsTask().Exception.InnerException;
}