Show / Hide Table of Contents

Class TaskHelper

Some helpers for tasks.

Inheritance
Object
TaskHelper
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: PeerTalk
Assembly: PeerTalk.dll
Syntax
public static class TaskHelper

Methods

| Improve this Doc View Source

ParallelForEachAsync<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

Copied from https://houseofcat.io/tutorials/csharp/async/parallelforeachasync

| Improve this Doc View Source

WhenAnyResultAsync<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 T>.

Type Parameters
Name Description
T

The result type of the tasks.

Remarks

Returns the result of the first task that is not faulted or canceled.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX