Class AsyncDelegate
Provides set of methods for asynchronous invocation of various delegates.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.dll
Syntax
public static class AsyncDelegate
Remarks
In .NET Core, BeginInvoke and EndInvoke methods of delegate type are not supported. This class provides alternative approach which allows to invoke delegate asynchronously with full support of async/await feature.
Methods
| Improve this Doc View SourceBeginInvoke(Action<Object, CancellationToken>, Object, AsyncCallback, TaskCreationOptions, TaskScheduler, CancellationToken)
Invokes synchronous delegate asynchronously.
Declaration
public static Task BeginInvoke(this Action<object, CancellationToken> action, object state, AsyncCallback callback, TaskCreationOptions options = TaskCreationOptions.None, TaskScheduler scheduler = null, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<Object, CancellationToken> | action | The action to invoke asynchronously. |
Object | state | The state object to be passed to the action. |
AsyncCallback | callback | The callback to be invoked on completion. |
TaskCreationOptions | options | The task scheduling options. |
TaskScheduler | scheduler | The task scheduler. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous execution of the action. |
BeginInvoke(Action<Object>, Object, AsyncCallback, TaskCreationOptions, TaskScheduler)
Invokes synchronous delegate asynchronously.
Declaration
public static Task BeginInvoke(this Action<object> action, object state, AsyncCallback callback, TaskCreationOptions options = TaskCreationOptions.None, TaskScheduler scheduler = null)
Parameters
Type | Name | Description |
---|---|---|
Action<Object> | action | The action to invoke asynchronously. |
Object | state | The state object to be passed to the action. |
AsyncCallback | callback | The callback to be invoked on completion. |
TaskCreationOptions | options | The task scheduling options. |
TaskScheduler | scheduler | The task scheduler. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous execution of the action. |
BeginInvoke<TResult>(Func<Object, TResult>, Object, AsyncCallback, TaskCreationOptions, TaskScheduler)
Invokes synchronous delegate asynchronously.
Declaration
public static Task<TResult> BeginInvoke<TResult>(this Func<object, TResult> function, object state, AsyncCallback callback, TaskCreationOptions options = TaskCreationOptions.None, TaskScheduler scheduler = null)
Parameters
Type | Name | Description |
---|---|---|
Func<Object, TResult> | function | The function to invoke asynchronously. |
Object | state | The state object to be passed to the action. |
AsyncCallback | callback | The callback to be invoked on completion. |
TaskCreationOptions | options | The task scheduling options. |
TaskScheduler | scheduler | The task scheduler. |
Returns
Type | Description |
---|---|
Task<TResult> | The task representing asynchronous execution of the action. |
Type Parameters
Name | Description |
---|---|
TResult | The type of result of asynchronous operation. |
BeginInvoke<TResult>(Func<Object, CancellationToken, TResult>, Object, AsyncCallback, TaskCreationOptions, TaskScheduler, CancellationToken)
Invokes synchronous delegate asynchronously.
Declaration
public static Task<TResult> BeginInvoke<TResult>(this Func<object, CancellationToken, TResult> function, object state, AsyncCallback callback, TaskCreationOptions options = TaskCreationOptions.None, TaskScheduler scheduler = null, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Func<Object, CancellationToken, TResult> | function | The function to invoke asynchronously. |
Object | state | The state object to be passed to the action. |
AsyncCallback | callback | The callback to be invoked on completion. |
TaskCreationOptions | options | The task scheduling options. |
TaskScheduler | scheduler | The task scheduler. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task<TResult> | The task representing asynchronous execution of the action. |
Type Parameters
Name | Description |
---|---|
TResult | The type of result of asynchronous operation. |
InvokeAsync(Action, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync(this Action action, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action | action | The action to invoke asynchronously. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
InvokeAsync(EventHandler, Object, EventArgs, CancellationToken)
Invokes event handlers asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync(this EventHandler handler, object sender, EventArgs args, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
EventHandler | handler | A set event handlers combined as single delegate. |
Object | sender | Event sender. |
EventArgs | args | Event arguments. |
CancellationToken | token | Optional cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | An object representing state of the asynchronous invocation. |
InvokeAsync<TDelegate>(TDelegate, Action<TDelegate>, CancellationToken)
Invokes a delegate of arbitrary type asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<TDelegate>(this TDelegate delegate, Action<TDelegate> invoker, CancellationToken token = default(CancellationToken))
where TDelegate : MulticastDelegate
Parameters
Type | Name | Description |
---|---|---|
TDelegate | delegate | A delegate to be invoked asynchronously. |
Action<TDelegate> | invoker | Synchronous invoker of the delegate from invocation list. |
CancellationToken | token | Cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | A task allows to control asynchronous invocation of methods attached to the multicast delegate. |
Type Parameters
Name | Description |
---|---|
TDelegate | Type of delegate to invoke. |
InvokeAsync<T>(Action<T>, T, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T>(this Action<T> action, T arg, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T> | action | The action to invoke asynchronously. |
T | arg | The action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T | Type of the action argument. |
InvokeAsync<TEventArgs>(EventHandler<TEventArgs>, Object, TEventArgs, CancellationToken)
Invokes event handlers asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<TEventArgs>(this EventHandler<TEventArgs> handler, object sender, TEventArgs args, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
EventHandler<TEventArgs> | handler | A set event handlers combined as single delegate. |
Object | sender | Event sender. |
TEventArgs | args | Event arguments. |
CancellationToken | token | Optional cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | An object representing state of the asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
TEventArgs | Type of event object. |
InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
T3 | arg3 | The third action argument. |
T4 | arg4 | The fourth action argument. |
T5 | arg5 | The fifth action argument. |
T6 | arg6 | The sixth action argument. |
T7 | arg7 | The seventh action argument. |
T8 | arg8 | The eighth action argument. |
T9 | arg9 | The ninth action argument. |
T10 | arg10 | The tenth action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
T3 | Type of the third action argument. |
T4 | Type of the fourth action argument. |
T5 | Type of the fifth action argument. |
T6 | Type of the sixth action argument. |
T7 | Type of the seventh action argument. |
T8 | Type of the eighth action argument. |
T9 | Type of the ninth action argument. |
T10 | Type of the tenth action argument. |
InvokeAsync<T1, T2>(Action<T1, T2>, T1, T2, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2>(this Action<T1, T2> action, T1 arg1, T2 arg2, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
InvokeAsync<T1, T2, T3>(Action<T1, T2, T3>, T1, T2, T3, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2, T3>(this Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
T3 | arg3 | The third action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
T3 | Type of the third action argument. |
InvokeAsync<T1, T2, T3, T4>(Action<T1, T2, T3, T4>, T1, T2, T3, T4, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2, T3, T4>(this Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
T3 | arg3 | The third action argument. |
T4 | arg4 | The fourth action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
T3 | Type of the third action argument. |
T4 | Type of the fourth action argument. |
InvokeAsync<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5>, T1, T2, T3, T4, T5, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2, T3, T4, T5>(this Action<T1, T2, T3, T4, T5> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4, T5> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
T3 | arg3 | The third action argument. |
T4 | arg4 | The fourth action argument. |
T5 | arg5 | The fifth action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
T3 | Type of the third action argument. |
T4 | Type of the fourth action argument. |
T5 | Type of the fifth action argument. |
InvokeAsync<T1, T2, T3, T4, T5, T6>(Action<T1, T2, T3, T4, T5, T6>, T1, T2, T3, T4, T5, T6, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2, T3, T4, T5, T6>(this Action<T1, T2, T3, T4, T5, T6> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4, T5, T6> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
T3 | arg3 | The third action argument. |
T4 | arg4 | The fourth action argument. |
T5 | arg5 | The fifth action argument. |
T6 | arg6 | The sixth action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
T3 | Type of the third action argument. |
T4 | Type of the fourth action argument. |
T5 | Type of the fifth action argument. |
T6 | Type of the sixth action argument. |
InvokeAsync<T1, T2, T3, T4, T5, T6, T7>(Action<T1, T2, T3, T4, T5, T6, T7>, T1, T2, T3, T4, T5, T6, T7, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2, T3, T4, T5, T6, T7>(this Action<T1, T2, T3, T4, T5, T6, T7> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4, T5, T6, T7> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
T3 | arg3 | The third action argument. |
T4 | arg4 | The fourth action argument. |
T5 | arg5 | The fifth action argument. |
T6 | arg6 | The sixth action argument. |
T7 | arg7 | The seventh action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
T3 | Type of the third action argument. |
T4 | Type of the fourth action argument. |
T5 | Type of the fifth action argument. |
T6 | Type of the sixth action argument. |
T7 | Type of the seventh action argument. |
InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8>(Action<T1, T2, T3, T4, T5, T6, T7, T8>, T1, T2, T3, T4, T5, T6, T7, T8, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8>(this Action<T1, T2, T3, T4, T5, T6, T7, T8> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4, T5, T6, T7, T8> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
T3 | arg3 | The third action argument. |
T4 | arg4 | The fourth action argument. |
T5 | arg5 | The fifth action argument. |
T6 | arg6 | The sixth action argument. |
T7 | arg7 | The seventh action argument. |
T8 | arg8 | The eighth action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
T3 | Type of the third action argument. |
T4 | Type of the fourth action argument. |
T5 | Type of the fifth action argument. |
T6 | Type of the sixth action argument. |
T7 | Type of the seventh action argument. |
T8 | Type of the eighth action argument. |
InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9>, T1, T2, T3, T4, T5, T6, T7, T8, T9, CancellationToken)
Invokes action asynchronously.
Declaration
public static AsyncDelegateFuture InvokeAsync<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> | action | The action to invoke asynchronously. |
T1 | arg1 | The first action argument. |
T2 | arg2 | The second action argument. |
T3 | arg3 | The third action argument. |
T4 | arg4 | The fourth action argument. |
T5 | arg5 | The fifth action argument. |
T6 | arg6 | The sixth action argument. |
T7 | arg7 | The seventh action argument. |
T8 | arg8 | The eighth action argument. |
T9 | arg9 | THe ninth action argument. |
CancellationToken | token | Invocation cancellation token. |
Returns
Type | Description |
---|---|
AsyncDelegateFuture | The task representing state of asynchronous invocation. |
Type Parameters
Name | Description |
---|---|
T1 | Type of the first action argument. |
T2 | Type of the second action argument. |
T3 | Type of the third action argument. |
T4 | Type of the fourth action argument. |
T5 | Type of the fifth action argument. |
T6 | Type of the sixth action argument. |
T7 | Type of the seventh action argument. |
T8 | Type of the eighth action argument. |
T9 | Type of the ninth action argument. |