TcpClient 멤버가있는 클래스가 있습니다. 예 :구성원 TcpClient 제대로 처리하기
class CustomNetClient
{
TcpClient tcp;
NetworkStream ns;
//...
}
제대로 닫히고 싶습니다.
class CustomNetClient
{
TcpClient tcp;
NetworkStream ns;
public CustomNetClient()
{
tcp = new TcpClient("1.1.1.1",80);
ns = tcp.GetNetworkStream();
}
public void Dispose()
{
tcp.Close();
ns.Close();
}
//...
}
을 그리고 응용 프로그램에서 나는 using
와 CustomNetClient
전화 : 그래서 IDisposable
을 구현했습니다.
//...
using(CustomNetClient nc=new CustomNetClient)
{
// This will be a long long process, connection will stay open
}
이 방법이 좋은 방법인가요? 또는 제안 사항이나 의구심이 있습니까?