I am trying to add a "timeout" for the ReadAsync
method from a NetworkStream
.
I want to cancel the ReadAsync
after a specific time.
For example:
ctsTimeout.CancelAfter(10);
int bytesRead = await nsStream.ReadAsync(newArr, 0, newArr.Length, ctsTimeout.Token);
But the method is still waiting for a response from the server.
Is it possible to cancel this method in its reading state?