# DurableTaskExtensions.WhenAny(IReadOnlyList&lt;ScheduledTask&gt;, CancellationToken)

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.durabletaskextensions/) | [Methods](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.durabletaskextensions/methods/)

[Source](https://github.com/dotnet/orleans/blob/6a0e937f544c35ffcf11b37e4c2b7de5a1580a03/src/Orleans.Durable.Abstractions/DurableTaskExtensions.Combinators.cs)

```csharp
public static Task<ScheduledTask> WhenAny(this IReadOnlyList<ScheduledTask> tasks, CancellationToken cancellationToken = default(CancellationToken))
```

Returns the first scheduled task whose response completes, including failed or canceled durable responses. Wait cancellation and transport failures are propagated, and losing waits are canceled without canceling the durable tasks. Candidates are captured when this method is called.

### Parameters

- `tasks` (`IReadOnlyList<ScheduledTask>`)
- `cancellationToken` (`CancellationToken`)

### Exceptions

- `System.ArgumentOutOfRangeException`: `tasks` is empty.
- `System.InvalidOperationException`: The host's wait for the selected task returned an incomplete response.
