Class AwaitExtensions
- Namespace
- Microsoft.VisualStudio.Threading
- Assembly
- Microsoft.VisualStudio.Threading.dll
Extension methods and awaitables for .NET 4.5.
public static class AwaitExtensions
- Inheritance
-
AwaitExtensions
- Inherited Members
Methods
ConfigureAwait(YieldAwaitable, bool)
Converts a YieldAwaitable to a AwaitExtensions.ConfiguredTaskYieldAwaitable.
public static AwaitExtensions.ConfiguredTaskYieldAwaitable ConfigureAwait(this YieldAwaitable yieldAwaitable, bool continueOnCapturedContext)
Parameters
yieldAwaitable
YieldAwaitableThe result of Yield().
continueOnCapturedContext
boolA value indicating whether the continuation should run on the captured SynchronizationContext, if any.
Returns
- AwaitExtensions.ConfiguredTaskYieldAwaitable
An awaitable.
ConfigureAwaitForAggregateException(Task, bool)
Returns an awaitable that will throw AggregateException from the Exception property of the task if it faults.
public static AwaitExtensions.AggregateExceptionAwaitable ConfigureAwaitForAggregateException(this Task task, bool continueOnCapturedContext = true)
Parameters
Returns
- AwaitExtensions.AggregateExceptionAwaitable
An awaitable that may throw AggregateException.
Remarks
Awaiting a Task with its default TaskAwaiter only throws the first exception within InnerExceptions. When you do not want to lose the detail of other inner exceptions, use this extension method.
Exceptions
- AggregateException
Thrown when
task
faults.
ConfigureAwaitRunInline(Task)
Gets an awaitable that schedules the continuation with a preference to executing synchronously on the callstack that completed the Task, without regard to thread ID or any SynchronizationContext that may be applied when the continuation is scheduled or when the antecedent completes.
public static AwaitExtensions.ExecuteContinuationSynchronouslyAwaitable ConfigureAwaitRunInline(this Task antecedent)
Parameters
antecedent
TaskThe task to await on.
Returns
- AwaitExtensions.ExecuteContinuationSynchronouslyAwaitable
An awaitable.
Remarks
If there is not enough stack space remaining on the thread that is completing the antecedent
Task,
the continuation may be scheduled on the threadpool.
ConfigureAwaitRunInline<T>(Task<T>)
Gets an awaitable that schedules the continuation with a preference to executing synchronously on the callstack that completed the Task, without regard to thread ID or any SynchronizationContext that may be applied when the continuation is scheduled or when the antecedent completes.
public static AwaitExtensions.ExecuteContinuationSynchronouslyAwaitable<T> ConfigureAwaitRunInline<T>(this Task<T> antecedent)
Parameters
antecedent
Task<T>The task to await on.
Returns
- AwaitExtensions.ExecuteContinuationSynchronouslyAwaitable<T>
An awaitable.
Type Parameters
T
The type of value returned by the awaited Task.
Remarks
If there is not enough stack space remaining on the thread that is completing the antecedent
Task,
the continuation may be scheduled on the threadpool.
GetAwaiter(SynchronizationContext)
Gets an awaiter that schedules continuations on the specified SynchronizationContext.
public static AwaitExtensions.SynchronizationContextAwaiter GetAwaiter(this SynchronizationContext synchronizationContext)
Parameters
synchronizationContext
SynchronizationContextThe synchronization context used to execute continuations.
Returns
- AwaitExtensions.SynchronizationContextAwaiter
An awaitable.
Remarks
The awaiter that is returned will always result in yielding, even if already executing within the specified synchronizationContext
.
GetAwaiter(TaskScheduler)
Gets an awaiter that schedules continuations on the specified scheduler.
public static AwaitExtensions.TaskSchedulerAwaiter GetAwaiter(this TaskScheduler scheduler)
Parameters
scheduler
TaskSchedulerThe task scheduler used to execute continuations.
Returns
- AwaitExtensions.TaskSchedulerAwaiter
An awaitable.
GetAwaiter(WaitHandle)
Provides await functionality for ordinary WaitHandles.
public static TaskAwaiter GetAwaiter(this WaitHandle handle)
Parameters
handle
WaitHandleThe handle to wait on.
Returns
- TaskAwaiter
The awaiter.
SwitchTo(TaskScheduler, bool)
Gets an awaitable that schedules continuations on the specified scheduler.
public static AwaitExtensions.TaskSchedulerAwaitable SwitchTo(this TaskScheduler scheduler, bool alwaysYield = false)
Parameters
scheduler
TaskSchedulerThe task scheduler used to execute continuations.
alwaysYield
boolA value indicating whether the caller should yield even if already executing on the desired task scheduler.
Returns
- AwaitExtensions.TaskSchedulerAwaitable
An awaitable.
WaitForChangeAsync(RegistryKey, bool, RegistryChangeNotificationFilters, CancellationToken)
Returns a Task that completes when the specified registry key changes.
public static Task WaitForChangeAsync(this RegistryKey registryKey, bool watchSubtree = true, RegistryChangeNotificationFilters change = RegistryChangeNotificationFilters.Subkey | RegistryChangeNotificationFilters.Value, CancellationToken cancellationToken = default)
Parameters
registryKey
RegistryKeyThe registry key to watch for changes.
watchSubtree
booltrue to watch the keys descendent keys as well; false to watch only this key without descendents.
change
RegistryChangeNotificationFiltersIndicates the kinds of changes to watch for.
cancellationToken
CancellationTokenA token that may be canceled to release the resources from watching for changes and complete the returned Task as canceled.
Returns
- Task
A task that completes when the registry key changes, the handle is closed, or upon cancellation.
WaitForExitAsync(Process, CancellationToken)
Returns a task that completes when the process exits and provides the exit code of that process.
public static Task<int> WaitForExitAsync(this Process process, CancellationToken cancellationToken = default)
Parameters
process
ProcessThe process to wait for exit.
cancellationToken
CancellationTokenA token whose cancellation will cause the returned Task to complete before the process exits in a faulted state with an OperationCanceledException. This token has no effect on the
process
itself.