-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net.Sockets
Milestone
Description
EDITED 3/14/2022 by @stephentoub:
namespace System.Net.Sockets
{
public class TcpListener
+ : IDisposable
{
+ void IDisposable.Dispose() => Stop();
}
}TcpListener is essentially a convenience wrapper around a Socket in listen mode. Sockets are disposable, but TcpListener is not. Instead, you are expected to call the Stop() method.
Implementing IDisposable enables "using" syntax and matches common library practice.
Consider that the sample code for TcpListener explicitly uses a try/finally to ensure that Stop() is called properly: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener?view=net-6.0
See also https://stackoverflow.com/questions/33667149/why-tcplistener-does-not-implement-idisposable
GSPP, WeihanLi, Tan90909090 and AlexRadch
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net.Sockets