how to cancel an awaiting task c#
- by user1748906
I am trying to cancel a task awaiting for network IO using CancellationTokenSource, but I have to wait until TcpClient connects:
try
{
while (true)
{
token.Token.ThrowIfCancellationRequested();
Thread.Sleep(int.MaxValue); //simulating a TcpListener waiting for request
}
}
any ideas ?
Secondly, is it OK to start each client in a separate task ?