Struct TaskSchedulerCapture
A lightweight object capable of extracting TaskScheduler instances from the current SynchronizationContext and capturing them.
public readonly struct TaskSchedulerCapture
- Inherited Members
- Extension Methods
Constructors
TaskSchedulerCapture(TaskSchedulerCaptureStrategy)
Creates a new TaskSchedulerCapture instance based on the provided strategy
.
public TaskSchedulerCapture(TaskSchedulerCaptureStrategy strategy)
Parameters
strategy
TaskSchedulerCaptureStrategyAn option that defines the TaskSchedulerCapture instance's behavior.
Remarks
See TaskSchedulerCaptureStrategy for available strategies.
TaskSchedulerCapture(TaskScheduler?)
Creates a new TaskSchedulerCapture instance with an explicit TaskScheduler.
public TaskSchedulerCapture(TaskScheduler? scheduler)
Parameters
scheduler
TaskSchedulerAn explicit TaskScheduler instance to capture.
Methods
FromSynchronizationContext(SynchronizationContext)
Returns TaskScheduler instance associated with the provided context
.
public static TaskScheduler FromSynchronizationContext(SynchronizationContext context)
Parameters
context
SynchronizationContextSynchronizationContext instance from which to get the TaskScheduler instance.
Returns
- TaskScheduler
TaskScheduler instance associated with the provided
context
.
GetCurrentScheduler()
Returns the current TaskScheduler instance.
public static TaskScheduler GetCurrentScheduler()
Returns
- TaskScheduler
Current TaskScheduler instance.
Remarks
When Current synchronization context is not null, then this method returns the result of FromCurrentSynchronizationContext() invocation, otherwise returns Current task scheduler.
TryGetScheduler()
Returns the captured TaskScheduler instance or the current TaskScheduler if this capture has been created with the Lazy option.
public TaskScheduler? TryGetScheduler()
Returns
- TaskScheduler
TaskScheduler associated with this capture.