クライアントがサーバーの接続を失うたびに、サーバーを継続的に検索する再接続ループが発生します。
このループが実行されると、コンピューターの速度が低下して停止するまで、接続を試みるたびにconhost.exeとcsc.exeのプロセスが生成されます。
誰かがこれらのプロセスを作成するものを知っていますか?
つまり、接続が失敗したり接続が失われたりするたびに、Initializeを呼び出します。これにより、すべてのコンポーネントが適切に破棄されてから、すべてが再初期化されます。
NetworkInterfaceおよびTcpInterfaceのメソッドの初期化:
public void Initialize()
{
if (ni != null)
{
ni.Dispose();
GC.Collect();
}
if (tcpInterface != null)
{
tcpInterface.Dispose();
}
tcpInterface = new TcpInterface();
if (!string.IsNullOrEmpty(ipAddress))
{
tcpInterface.Settings = new TcpSettings
{
RemoteIp = ipAddress,
Port = _port,
PacketDenotesLength = false
};
}
tcpInterface.NewConnection += new TcpInterface.TcpNetworkStateEventHandler(tcpInterface_NewConnection);
tcpInterface.FailConnection += new TcpInterface.ConnectionEventHandler(tcpInterface_FailConnection);
tcpInterface.ReceivePacket += new TcpInterface.TcpInterfacePacketEventHandler(tcpInterface_ReceivePacket);
tcpInterface.LoseConnection += new TcpInterface.TcpNetworkStateEventHandler(tcpInterface_LoseConnection);
ni = new NetworkInterface<string, PacketInfo>();
ni.Services.Register("TcpInterface", tcpInterface);
ni.Initialize();
}
TcpInterfaceの廃棄:
public void Dispose()
{
if (TcpClient != null)// && TcpClient.Connected)
{
if (TcpClient.Connected)
{
NetworkStream stream = TcpClient.GetStream();
if (stream != null)
{
stream.Close();
}
}
TcpClient.Close();
TcpClient = null;
}
Buffer = null;
BufferBuilder = null;
}
niのために処分する:
public void Dispose()
{
Services.Dispose();
}