Good day. I work with UdpClient and have wrapper upon it.
For reading I have asynchronous method:
private async Task Recei
The only way to cancel a pending receive is to disconnect/stop/dispose as you did. This is correct. You need to catch and ignore that exception.
It is an unfortunate design problem with the .NET Framework that this is the only way to do it.
Note, that WithCancellation does not cancel the IO. The Receive is still running. That's why WithCancellation must be followed by disposing of the socket to make sure that there are no further pending IOs.