# DiagnosticEventCollector.WaitForEventCountAsync(string, int, TimeSpan, CancellationToken)

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/) | [Methods](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs#L186-L223)

```csharp
public Task<IReadOnlyList<DiagnosticEvent>> WaitForEventCountAsync(string eventName, int expectedCount, TimeSpan timeout, CancellationToken cancellationToken = default(CancellationToken))
```

Waits until at least the specified number of events with the given name have been captured.

### Parameters

- `eventName` (`string`): The name of the event to count.
- `expectedCount` (`int`): The minimum number of events expected.
- `timeout` (`TimeSpan`): The maximum time to wait.
- `cancellationToken` (`CancellationToken`): A cancellation token.

### Returns

All captured events with the specified name.

### Exceptions

- `System.TimeoutException`: Thrown if the expected count is not reached within the timeout.
