I'm listening to a UDP socket by using an UdpClient
:
UdpClient udpClient = new(new IPEndPoint(myLocalAddress, 12345));
udpClient.Receive();
Indeed, this blocks. Because of this, I moved this code in a separate Task
.
On a change of the network, I will stop no longer needed UdpClient
s. For this, I use the NetworkChange.NetworkAddressChanged
event.
How can I stop the listening of the UdpClient
s? The UdpClient.Receive
method does not allow a CancellationToken
.