UdpClient.Dispose() Method
Releases the unmanaged resources used by the UdpClient and optionally releases the managed resources.
Syntax
public void Dispose();
Remarks
The Dispose() method releases all resources used by the UdpClient instance. This method is called automatically when the UdpClient object is disposed of, for example, when it is no longer needed. It is recommended to call Dispose() explicitly when you are finished with the UdpClient to ensure that resources are released promptly.
This method implements the IDisposable.Dispose() pattern. When you inherit from UdpClient, you should not override the Dispose() method. Instead, override the protected virtual Dispose(Boolean) method to release managed and unmanaged resources.
Tip
Using a using statement is the recommended way to ensure that the Dispose() method is called automatically, even if an exception occurs.
using (UdpClient udpClient = new UdpClient(11000))
{
// Use the UdpClient instance here...
// udpClient.Dispose() will be called automatically when exiting the 'using' block.
}
Exceptions
This method does not throw exceptions.
Requirements
Namespace: System.Net.Sockets
Assembly: System.Net.Sockets.dll
See Also
- UdpClient Class
- System.Net.Sockets Namespace
- IDisposable Interface
- Basic UDP examples