Class Async
Task related utilities.
Namespace: Neon.Tasks
Assembly: Neon.Common.dll
Syntax
public static class Async
Methods
ForEachAsync<TWorkItem>(IEnumerable<TWorkItem>, Func<TWorkItem, CancellationToken, Task>, CancellationToken, int)
Iterates over a set of work items and executes an async action for each item. The method returns when all of the actions have completed.
Declaration
public static Task ForEachAsync<TWorkItem>(IEnumerable<TWorkItem> workItems, Func<TWorkItem, CancellationToken, Task> action, CancellationToken cancellationToken, int maxParallel = 1)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TWorkItem> | workItems | The work item collection. |
Func<TWorkItem, CancellationToken, Task> | action | The async action to be executed on each work item. |
CancellationToken | cancellationToken | The cancellation token. |
int | maxParallel | Optionally specifies the maximum number of tasks to execute in parallel (defaults to |
Returns
Type | Description |
---|---|
Task | The tracking Task. |
Type Parameters
Name | Description |
---|---|
TWorkItem | The work item type. |
Remarks
The actions will be executed on threads from the thread pool which means that the number of tasks that can be executed in parallel will be limited by the number of available pooled threads.
note
The order in which work items are executed is not defined.
Exceptions
Type | Condition |
---|---|
AggregateException | Thrown when any of the actions failed. |
ForEachAsync<TWorkItem>(IEnumerable<TWorkItem>, Func<TWorkItem, Task>, int)
Iterates over a set of work items and executes an async action for each item. The method returns when all of the actions have completed.
Declaration
public static Task ForEachAsync<TWorkItem>(IEnumerable<TWorkItem> workItems, Func<TWorkItem, Task> action, int maxParallel = 1)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TWorkItem> | workItems | The work item collection. |
Func<TWorkItem, Task> | action | The async action to be executed on each work item. |
int | maxParallel | Optionally specifies the maximum number of tasks to execute in parallel (defaults to |
Returns
Type | Description |
---|---|
Task | The tracking Task. |
Type Parameters
Name | Description |
---|---|
TWorkItem | The work item type. |
Remarks
The actions will be executed on threads from the thread pool which means that the number of tasks that can be executed in parallel will be limited by the number of available pooled threads.
note
The order in which work items are executed is not defined.
Exceptions
Type | Condition |
---|---|
AggregateException | Thrown when any of the actions failed. |