Class SynchronizationContextExtensions
- Namespace
- CarinaStudio.Threading
- Assembly
- CarinaStudio.AppBase.Core.dll
Extensions for SynchronizationContext.
public static class SynchronizationContextExtensions
- Inheritance
-
SynchronizationContextExtensions
- Inherited Members
Methods
CancelDelayed(SynchronizationContext, object)
Cancel posted delayed call-back.
public static bool CancelDelayed(this SynchronizationContext synchronizationContext, object token)
Parameters
synchronizationContextSynchronizationContexttokenobjectToken returned from PostDelayed(SynchronizationContext, SendOrPostCallback, object?, int).
Returns
- bool
True if call-back cancelled successfully.
Post(SynchronizationContext, Action)
Post call-back.
public static void Post(this SynchronizationContext synchronizationContext, Action callback)
Parameters
synchronizationContextSynchronizationContextcallbackActionCall-back.
PostDelayed(SynchronizationContext, Action, int)
Post delayed call-back.
public static object PostDelayed(this SynchronizationContext synchronizationContext, Action callback, int delayMillis)
Parameters
synchronizationContextSynchronizationContextcallbackActionCall-back.
delayMillisintDelayed time in milliseconds.
Returns
- object
Token of posted delayed call-back.
PostDelayed(SynchronizationContext, Action, TimeSpan)
Post delayed call-back.
public static object PostDelayed(this SynchronizationContext synchronizationContext, Action callback, TimeSpan delay)
Parameters
synchronizationContextSynchronizationContextcallbackActionCall-back.
delayTimeSpanDelayed time.
Returns
- object
Token of posted delayed call-back.
PostDelayed(SynchronizationContext, SendOrPostCallback, object?, int)
Post delayed call-back.
public static object PostDelayed(this SynchronizationContext synchronizationContext, SendOrPostCallback callback, object? state, int delayMillis)
Parameters
synchronizationContextSynchronizationContextcallbackSendOrPostCallbackCall-back.
stateobjectCustom state pass to call-back.
delayMillisintDelayed time in milliseconds.
Returns
- object
Token of posted delayed call-back.
PostDelayed(SynchronizationContext, SendOrPostCallback, object?, TimeSpan)
Post delayed call-back.
public static object PostDelayed(this SynchronizationContext synchronizationContext, SendOrPostCallback callback, object? state, TimeSpan delay)
Parameters
synchronizationContextSynchronizationContextcallbackSendOrPostCallbackCall-back.
stateobjectCustom state pass to call-back.
delayTimeSpanDelayed time.
Returns
- object
Token of posted delayed call-back.
Send(SynchronizationContext, Action)
Call given call-back synchronously.
public static void Send(this SynchronizationContext synchronizationContext, Action callback)
Parameters
synchronizationContextSynchronizationContextcallbackActionCall-back.
SendAsync(SynchronizationContext, Action, CancellationToken)
Send action and wait for completion asynchronously.
public static Task SendAsync(this SynchronizationContext synchronizationContext, Action action, CancellationToken cancellationToken = default)
Parameters
synchronizationContextSynchronizationContextactionActionAction.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task of sending and performing action.
SendAsync(SynchronizationContext, Func<Task>, CancellationToken)
Send an asynchronous action and wait for completion asynchronously.
public static Task SendAsync(this SynchronizationContext synchronizationContext, Func<Task> asyncAction, CancellationToken cancellationToken = default)
Parameters
synchronizationContextSynchronizationContextasyncActionFunc<Task>Asynchronous action.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task of sending and performing action.
SendAsync<R>(SynchronizationContext, Func<Task<R>>, CancellationToken)
Send an asynchronous action and wait for result asynchronously.
public static Task<R> SendAsync<R>(this SynchronizationContext synchronizationContext, Func<Task<R>> asyncFunc, CancellationToken cancellationToken = default)
Parameters
synchronizationContextSynchronizationContextasyncFuncFunc<Task<R>>Asynchronous function to generate result.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<R>
Task of sending and performing action.
Type Parameters
R
SendAsync<R>(SynchronizationContext, Func<R>, CancellationToken)
Send action and wait for result asynchronously.
public static Task<R> SendAsync<R>(this SynchronizationContext synchronizationContext, Func<R> func, CancellationToken cancellationToken = default)
Parameters
synchronizationContextSynchronizationContextfuncFunc<R>Function to generate result.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<R>
Task of sending and performing action.
Type Parameters
R
Send<R>(SynchronizationContext, Func<R>)
Call given function and wait for result.
public static R Send<R>(this SynchronizationContext synchronizationContext, Func<R> func)
Parameters
synchronizationContextSynchronizationContextfuncFunc<R>Function.
Returns
- R
Result of function.
Type Parameters
RType of result.