为什么TcpListener没有实现IDisposable

问题描述 投票:0回答:2

为了更好地理解 .NET 网络部分的工作原理,我将浏览 TcpListener(Documentation, Reference Source) 类的参考源。引起我注意的是它拥有实现 IDisposable (Socket) 的对象,但本身并不实现 IDisposable。这有什么原因吗?

c# .net tcp idisposable tcplistener
2个回答
0
投票

因为当您使用基于

IPEndPoint
构造函数 时,
TcpListener
不拥有套接字。如果您打算重复使用所述
IPEndPoint
对象

,那么处置所述套接字将是非常粗鲁的

0
投票

从 net8.0 开始,

TcpListener
确实实现了
IDisposable
。对于上下文,您可以通读问题 TcpListener 应该实现 IDisposable #63114

© www.soinside.com 2019 - 2024. All rights reserved.