When trying to dispose of a UdpClient, I found that it's impossible. For the following:
UdpClient udpClient = new UdpClient();
udpClient.Dispose();
Visual Studio shows an error:
'System.Net.Sockets.UdpClient.Dispose(bool)' is inaccessible due to its protection level
Does this mean that I should inherit from UdpClient
and expose the Dispose
(Since it seems to be the consensus that whatever implements IDisposable should be disposed of)? Is there some reason we shouldn't use the class directly? Or is there simply nothing to dispose of after calling Close
?
Though a using
statement does work - it's not suitable when listening.
No you shouldn't.
you should call UdpClient.Close
...
After looking at the source here: http://referencesource.microsoft.com/#System/net/System/Net/Sockets/UDPClient.cs#7682e0ea2c48b5cb
It appears you can either call Close
or ((IDisposable)updClient).Dispose
but API-wise I think calling Close
is the way UDP client is intended to be used...
All this makes very little sense to me....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With