TaskFactory.ContinueWhenAny Method

Definition

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

Overloads

ContinueWhenAny(Task[], Action<Task>, TaskContinuationOptions)

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

ContinueWhenAny(Task[], Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

ContinueWhenAny(Task[], Action<Task>)

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

ContinueWhenAny(Task[], Action<Task>, CancellationToken)

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, TaskContinuationOptions)

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>)

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, CancellationToken)

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>)

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, CancellationToken)

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, TaskContinuationOptions)

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TResult>(Task[], Func<Task,TResult>)

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, CancellationToken)

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, TaskContinuationOptions)

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

ContinueWhenAny(Task[], Action<Task>, TaskContinuationOptions)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task ContinueWhenAny(System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task> continuationAction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);

Parameters

tasks
Task[]

The array of tasks from which to continue when one task completes.

continuationAction
Action<Task>

The action delegate to execute when one task in the tasks array completes.

continuationOptions
TaskContinuationOptions

The TaskContinuationOptions value that controls the behavior of the created continuation Task.

Returns

The new continuation Task.

Exceptions

One of the elements in the tasks array has been disposed.

The tasks array is null.

-or-

continuationAction is null.

continuationOptions specifies an invalid TaskContinuationOptions value.

The tasks array contains a null value.

-or-

The tasks array is empty.

Remarks

The NotOn* and OnlyOn* TaskContinuationOptions, which constrain for which TaskStatus states a continuation will be executed, are illegal with ContinueWhenAny.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny(Task[], Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task ContinueWhenAny(System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);

Parameters

tasks
Task[]

The array of tasks from which to continue when one task completes.

continuationAction
Action<Task>

The action delegate to execute when one task in the tasks array completes.

cancellationToken
CancellationToken

The CancellationToken that will be assigned to the new continuation task.

continuationOptions
TaskContinuationOptions

The TaskContinuationOptions value that controls the behavior of the created continuation Task.

scheduler
TaskScheduler

The TaskScheduler that is used to schedule the created continuation Task.

Returns

The new continuation Task.

Exceptions

The tasks array is null.

-or-

continuationAction is null.

-or-

scheduler is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

continuationOptions specifies an invalid TaskContinuationOptions value.

The provided CancellationToken has already been disposed.

Remarks

The NotOn* and OnlyOn* TaskContinuationOptions, which constrain for which TaskStatus states a continuation will be executed, are illegal with ContinueWhenAny.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny(Task[], Action<Task>)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task ContinueWhenAny(System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task> continuationAction);

Parameters

tasks
Task[]

The array of tasks from which to continue when one task completes.

continuationAction
Action<Task>

The action delegate to execute when one task in the tasks array completes.

Returns

The new continuation Task.

Exceptions

One of the elements in the tasks array has been disposed.

The tasks array is null.

-or-

The continuationAction argument is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

Examples

The following example shows how to use ContinueWhenAny and ContinueWhenAll:

C#
using System;
using System.Threading;
using System.Threading.Tasks;

class ContinueWhenMultiDemo
{
    // Demonstrated features:
    // 		Task.Factory
    //		TaskFactory.ContinueWhenAll()
    //		TaskFactory.ContinueWhenAny()
    //		Task.Wait()
    // Expected results:
    // 		Three tasks are created in parallel. 
    //		Each task for a different period of time prints a number and returns it.
    //      A ContinueWhenAny() task indicates the first of the three tasks to complete.
    //      A ContinueWhenAll() task sums up the results of the three tasks and prints out the total.
    // Documentation:
    //		http://msdn.microsoft.com/library/system.threading.tasks.taskfactory_members(VS.100).aspx
    static void Main()
    {
        // Schedule a list of tasks that return integer
        Task<int>[] tasks = new Task<int>[]
            {
                Task<int>.Factory.StartNew(() => 
                    {
                        Thread.Sleep(500);
                        Console.WriteLine("Task={0}, Thread={1}, x=5", Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
                        return 5;
                    }),

                Task<int>.Factory.StartNew(() => 
                    {
                        Thread.Sleep(10);
                        Console.WriteLine("Task={0}, Thread={1}, x=3", Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
                        return 3;
                    }),

                Task<int>.Factory.StartNew(() => 
                    {
                        Thread.Sleep(200);
                        Console.WriteLine("Task={0}, Thread={1}, x=2", Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
                        return 2;
                    })
            };

        // Schedule a continuation to indicate the result of the first task to complete
        Task.Factory.ContinueWhenAny(tasks, winner =>
        {
            // You would expect winning result = 3 on multi-core systems, because you expect
            // tasks[1] to finish first.
            Console.WriteLine("Task={0}, Thread={1} (ContinueWhenAny): Winning result = {2}", Task.CurrentId, Thread.CurrentThread.ManagedThreadId, winner.Result);
        });

        // Schedule a continuation that sums up the results of all tasks, then wait on it.
        // The list of antecendent tasks is passed as an argument by the runtime.
        Task.Factory.ContinueWhenAll(tasks,
            (antecendents) =>
            {
                int sum = 0;
                foreach (Task<int> task in antecendents)
                {
                    sum += task.Result;
                }

                Console.WriteLine("Task={0}, Thread={1}, (ContinueWhenAll): Total={2} (expected 10)", Task.CurrentId, Thread.CurrentThread.ManagedThreadId, sum);
            })
            .Wait();
    }
}

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny(Task[], Action<Task>, CancellationToken)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task ContinueWhenAny(System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task> continuationAction, System.Threading.CancellationToken cancellationToken);

Parameters

tasks
Task[]

The array of tasks from which to continue when one task completes.

continuationAction
Action<Task>

The action delegate to execute when one task in the tasks array completes.

cancellationToken
CancellationToken

The CancellationToken that will be assigned to the new continuation task.

Returns

The new continuation Task.

Exceptions

One of the elements in the tasks array has been disposed.

-or-

cancellationToken has already been disposed.

The tasks array is null.

-or-

The continuationAction argument is null.

The tasks array contains a null value.

-or-

The tasks array is empty .

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, TaskContinuationOptions)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TAntecedentResult,TResult>(System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>,TResult> continuationFunction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);

Type Parameters

TAntecedentResult

The type of the result of the antecedent tasks.

TResult

The type of the result that is returned by the continuationFunction delegate and associated with the created Task<TResult>.

Parameters

tasks
Task<TAntecedentResult>[]

The array of tasks from which to continue when one task completes.

continuationFunction
Func<Task<TAntecedentResult>,TResult>

The function delegate to execute asynchronously when one task in the tasks array completes.

continuationOptions
TaskContinuationOptions

The TaskContinuationOptions value that controls the behavior of the created continuation Task<TResult>.

Returns

The new continuation Task<TResult>.

Exceptions

One of the elements in the tasks array has been disposed.

The tasks array is null.

-or-

continuationFunction is null.

continuationOptions specifies an invalid TaskContinuationOptions value.

The tasks array contains a null value.

-or-

The tasks array is empty.

Remarks

The NotOn* and OnlyOn* TaskContinuationOptions, which constrain for which TaskStatus states a continuation will be executed, are illegal with ContinueWhenAny.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TAntecedentResult,TResult>(System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>,TResult> continuationFunction);

Type Parameters

TAntecedentResult

The type of the result of the antecedent tasks.

TResult

The type of the result that is returned by the continuationFunction delegate and associated with the created Task<TResult>.

Parameters

tasks
Task<TAntecedentResult>[]

The array of tasks from which to continue when one task completes.

continuationFunction
Func<Task<TAntecedentResult>,TResult>

The function delegate to execute asynchronously when one task in the tasks array completes.

Returns

The new continuation Task<TResult>.

Exceptions

One of the elements in the tasks array has been disposed.

The tasks array is null.

-or-

continuationFunction is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, CancellationToken)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TAntecedentResult,TResult>(System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken);

Type Parameters

TAntecedentResult

The type of the result of the antecedent tasks.

TResult

The type of the result that is returned by the continuationFunction delegate and associated with the created Task<TResult>.

Parameters

tasks
Task<TAntecedentResult>[]

The array of tasks from which to continue when one task completes.

continuationFunction
Func<Task<TAntecedentResult>,TResult>

The function delegate to execute asynchronously when one task in the tasks array completes.

cancellationToken
CancellationToken

The CancellationToken that will be assigned to the new continuation task.

Returns

The new continuation Task<TResult>.

Exceptions

One of the elements in the tasks array has been disposed.

-or-

The provided CancellationToken has already been disposed.

The tasks array is null.

-or-

continuationFunction is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TAntecedentResult,TResult>(System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);

Type Parameters

TAntecedentResult

The type of the result of the antecedent tasks.

TResult

The type of the result that is returned by the continuationFunction delegate and associated with the created Task<TResult>.

Parameters

tasks
Task<TAntecedentResult>[]

The array of tasks from which to continue when one task completes.

continuationFunction
Func<Task<TAntecedentResult>,TResult>

The function delegate to execute asynchronously when one task in the tasks array completes.

cancellationToken
CancellationToken

The CancellationToken that will be assigned to the new continuation task.

continuationOptions
TaskContinuationOptions

The TaskContinuationOptions value that controls the behavior of the created continuation Task<TResult>.

scheduler
TaskScheduler

The TaskScheduler that is used to schedule the created continuation Task<TResult>.

Returns

The new continuation Task<TResult>.

Exceptions

The tasks array is null.

-or-

continuationFunction is null.

-or-

scheduler is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

continuationOptions specifies an invalid TaskContinuationOptions value.

The provided CancellationToken has already been disposed.

Remarks

The NotOn* and OnlyOn* TaskContinuationOptions, which constrain for which TaskStatus states a continuation will be executed, are illegal with ContinueWhenAny.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task ContinueWhenAny<TAntecedentResult>(System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>> continuationAction);

Type Parameters

TAntecedentResult

The type of the result of the antecedent tasks.

Parameters

tasks
Task<TAntecedentResult>[]

The array of tasks from which to continue when one task completes.

continuationAction
Action<Task<TAntecedentResult>>

The action delegate to execute when one task in the tasks array completes.

Returns

The new continuation Task.

Exceptions

One of the elements in the tasks array has been disposed.

The tasks array is null.

-or-

continuationAction is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, CancellationToken)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task ContinueWhenAny<TAntecedentResult>(System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>> continuationAction, System.Threading.CancellationToken cancellationToken);

Type Parameters

TAntecedentResult

The type of the result of the antecedent tasks.

Parameters

tasks
Task<TAntecedentResult>[]

The array of tasks from which to continue when one task completes.

continuationAction
Action<Task<TAntecedentResult>>

The action delegate to execute when one task in the tasks array completes.

cancellationToken
CancellationToken

The CancellationToken that will be assigned to the new continuation task.

Returns

The new continuation Task.

Exceptions

One of the elements in the tasks array has been disposed.

-or-

The provided CancellationToken has already been disposed.

The tasks array is null.

-or-

continuationAction is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, TaskContinuationOptions)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task ContinueWhenAny<TAntecedentResult>(System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>> continuationAction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);

Type Parameters

TAntecedentResult

The type of the result of the antecedent tasks.

Parameters

tasks
Task<TAntecedentResult>[]

The array of tasks from which to continue when one task completes.

continuationAction
Action<Task<TAntecedentResult>>

The action delegate to execute when one task in the tasks array completes.

continuationOptions
TaskContinuationOptions

The TaskContinuationOptions value that controls the behavior of the created continuation Task.

Returns

The new continuation Task.

Exceptions

One of the elements in the tasks array has been disposed.

The tasks array is null.

-or-

continuationAction is null.

continuationOptions specifies an invalid TaskContinuationOptions value.

The tasks array contains a null value.

-or-

The tasks array is empty.

Remarks

The NotOn* and OnlyOn* TaskContinuationOptions, which constrain for which TaskStatus states a continuation will be executed, are illegal with ContinueWhenAny.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task ContinueWhenAny<TAntecedentResult>(System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);

Type Parameters

TAntecedentResult

The type of the result of the antecedent tasks.

Parameters

tasks
Task<TAntecedentResult>[]

The array of tasks from which to continue when one task completes.

continuationAction
Action<Task<TAntecedentResult>>

The action delegate to execute when one task in the tasks array completes.

cancellationToken
CancellationToken

The CancellationToken that will be assigned to the new continuation task.

continuationOptions
TaskContinuationOptions

The TaskContinuationOptions value that controls the behavior of the created continuation Task.

scheduler
TaskScheduler

The TaskScheduler that is used to schedule the created continuation Task<TResult>.

Returns

The new continuation Task.

Exceptions

The tasks array is null.

-or-

continuationAction is null.

-or-

paramref name="scheduler" /> is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

continuationOptions specifies an invalid TaskContinuationOptions value.

The provided CancellationToken has already been disposed.

Remarks

The NotOn* and OnlyOn* TaskContinuationOptions, which constrain for which TaskStatus states a continuation will be executed, are illegal with ContinueWhenAny.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TResult>(Task[], Func<Task,TResult>)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TResult>(System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task,TResult> continuationFunction);

Type Parameters

TResult

The type of the result that is returned by the continuationFunction delegate and associated with the created Task<TResult>.

Parameters

tasks
Task[]

The array of tasks from which to continue when one task completes.

continuationFunction
Func<Task,TResult>

The function delegate to execute asynchronously when one task in the tasks array completes.

Returns

The new continuation Task<TResult>.

Exceptions

One of the elements in the tasks array has been disposed.

The tasks array is null.

-or-

continuationFunction is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, CancellationToken)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TResult>(System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken);

Type Parameters

TResult

The type of the result that is returned by the continuationFunction delegate and associated with the created Task<TResult>.

Parameters

tasks
Task[]

The array of tasks from which to continue when one task completes.

continuationFunction
Func<Task,TResult>

The function delegate to execute asynchronously when one task in the tasks array completes.

cancellationToken
CancellationToken

The CancellationToken that will be assigned to the new continuation task.

Returns

The new continuation Task<TResult>.

Exceptions

One of the elements in the tasks array has been disposed.

-or-

The provided CancellationToken has already been disposed.

The tasks array is null.

-or-

continuationFunction is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, TaskContinuationOptions)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TResult>(System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);

Type Parameters

TResult

The type of the result that is returned by the continuationFunction delegate and associated with the created Task<TResult>.

Parameters

tasks
Task[]

The array of tasks from which to continue when one task completes.

continuationFunction
Func<Task,TResult>

The function delegate to execute asynchronously when one task in the tasks array completes.

continuationOptions
TaskContinuationOptions

The TaskContinuationOptions value that controls the behavior of the created continuation Task<TResult>.

Returns

The new continuation Task<TResult>.

Exceptions

One of the elements in the tasks array has been disposed.

The tasks array is null.

-or-

continuationFunction is null.

continuationOptions specifies an invalid TaskContinuationOptions value.

The tasks array contains a null value.

-or-

The tasks array is empty.

Remarks

The NotOn* and OnlyOn* TaskContinuationOptions, which constrain for which TaskStatus states a continuation will be executed, are illegal with ContinueWhenAny.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Source:
TaskFactory.cs
Source:
TaskFactory.cs
Source:
TaskFactory.cs

Creates a continuation Task<TResult> that will be started upon the completion of any Task in the provided set.

C#
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TResult>(System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);

Type Parameters

TResult

The type of the result that is returned by the continuationFunction delegate and associated with the created Task<TResult>.

Parameters

tasks
Task[]

The array of tasks from which to continue when one task completes.

continuationFunction
Func<Task,TResult>

The function delegate to execute asynchronously when one task in the tasks array completes.

cancellationToken
CancellationToken

The CancellationToken that will be assigned to the new continuation task.

continuationOptions
TaskContinuationOptions

The TaskContinuationOptions value that controls the behavior of the created continuation Task<TResult>.

scheduler
TaskScheduler

The TaskScheduler that is used to schedule the created continuation Task<TResult>.

Returns

The new continuation Task<TResult>.

Exceptions

The tasks array is null.

-or-

continuationFunction is null.

-or-

scheduler is null.

The tasks array contains a null value.

-or-

The tasks array is empty.

continuationOptions specifies an invalid TaskContinuationOptions value.

The provided CancellationToken has already been disposed.

Remarks

The NotOn* and OnlyOn* TaskContinuationOptions, which constrain for which TaskStatus states a continuation will be executed, are illegal with ContinueWhenAny.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0