Class TaskHelper
Some helpers for tasks.
Inherited Members
Namespace: PeerTalk
Assembly: PeerTalk.dll
Syntax
public static class TaskHelper
Methods
| Improve this Doc View SourceParallelForEachAsync<T>(IEnumerable<T>, Func<T, Task>, Int32)
Run async tasks in parallel,
Declaration
public static Task ParallelForEachAsync<T>(this IEnumerable<T> source, Func<T, Task> funcBody, int maxDoP = 4)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | source | A sequence of some data. |
| Func<T, Task> | funcBody | The async code to perform. |
| Int32 | maxDoP | The number of partitions to create. |
Returns
| Type | Description |
|---|---|
| Task | A Task to await. |
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
| Improve this Doc View SourceWhenAnyResultAsync<T>(IEnumerable<Task<T>>, CancellationToken)
Gets the first result from a set of tasks.
Declaration
public static Task<T> WhenAnyResultAsync<T>(IEnumerable<Task<T>> tasks, CancellationToken cancel)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Task<T>> | tasks | The tasks to perform. |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
| Type | Description |
|---|---|
| Task<T> | A task that represents the asynchronous operation. The task's result is
a |
Type Parameters
| Name | Description |
|---|---|
| T | The result type of the |
Remarks
Returns the result of the first task that is not faulted or canceled.