Socket オブジェクトと NetworkStream オブジェクトを使用するクラスを破棄する最善の方法を誰かが知っているかどうか疑問に思っていましたか? 問題のクラスには、NetworkStream のインスタンスと、NetworkStream の作成に使用される Socket のインスタンスがあります。
this.socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp)
{
ReceiveBufferSize = 65536,
SendBufferSize = 150
};
this.socket.Connect(
new IPEndPoint(
IPAddress.Parse(
Properties.Settings.Default.MpsServer2),
Properties.Settings.Default.MpsPort2));
this.stream = new NetworkStream(
this.socket, true);
私の Dispose メソッドでは、これを行う必要がありますか?
this.stream.Close();
this.socket.Shutdown(SocketShutdown.Both);
this.socket.Close();
これはすべて必要ですか、それともやり過ぎですか?