-
-
Notifications
You must be signed in to change notification settings - Fork 176
Open
Description
Task.Delay(-1, token) is creating a Task for every client that is running forever:
| var cancellationTask = Task.Delay(-1, token); |
A quick and dirty workaround would be this:
private async Task<bool> DelayTask(CancellationToken token1, CancellationToken token2)
{
while (!token1.IsCancellationRequested && !token2.IsCancellationRequested)
{
await Task.Delay(100);
}
return true;
}
public async Task<TcpClient> WaitAnyTcpClientAsync(CancellationToken token)
{
var tokenToDispose = new CancellationTokenSource();
var cancellationTask = Task.Run(() => DelayTask(token, tokenToDispose.Token));
do
{
...
}
while (result == null);
tokenToDispose.Cancel();
}
BrunoJuchli
Metadata
Metadata
Assignees
Labels
No labels