Task cancellation in UDPClient.RecieveAsync not triggering
I'm trying to recieve some UDP data, but give up if it hasnt been gotten within 40 ms.
I think the recommended way would be to pass in a TaskCancellationToken where the source has had a call to CancelAfter. However the task doesnt appear to be cancelled at all. When i change my approach and use Task.WhenAny, waiting on either udp or Task.Delay it does work correctly.
When i disconnect the device i'm connecting to it just hangs on RecieveFrom forever. I tried the overloads in UDPClient and in the underlying socket to no avail. Anything im doing wrong?
1 Reply
One issue is that you can’t always reuse the CTS
You have to recreate it once a timeout occurred
And you have to dispose it
TryReset will tell you what to do