# ScheduledTask&lt;TResult&gt;.WaitAsync(TimeSpan, CancellationToken)

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

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

```csharp
public Task<TResult> WaitAsync(TimeSpan timeout, CancellationToken cancellationToken = default(CancellationToken))
```

Waits for and returns the successful result, and requests durable cancellation of the task once `timeout` elapses.

### Parameters

- `timeout` (`TimeSpan`): The time to wait before requesting cancellation, which is zero or positive.
- `cancellationToken` (`CancellationToken`): A token which abandons the wait. It doesn't cancel the task.

### Returns

The task's result, including a result which it returns after observing the timeout's cancellation request.

### Exceptions

- `System.ArgumentOutOfRangeException`: `timeout` is negative, including `System.Threading.Timeout.InfiniteTimeSpan`; await the task to wait without a timeout. Outside a durable execution, `timeout` also exceeds the longest timer interval which `System.Threading.CancellationTokenSource.CancelAfter(System.TimeSpan)` accepts.
- `System.TimeoutException`: The timeout elapsed, and the task ended canceled.
