Whenever my client loses connection of the server, I have a re-connection loop which continuously looks for the server.
As this loop runs, it generates a process of conhost.exe and csc.exe every time it tries to connect until the computer slows to a halt.
Does anyone know what would create these processes?
So what happens, is anytime there is a failconnection or a loseconnection, I call Initialize. This should properly dispose all components and then reinitialize them all.
Initialize Method for NetworkInterface and 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();
}
Dipose for 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;
}
Dispose for ni:
public void Dispose()
{
Services.Dispose();
}
csc.exe is C# compiler.
do you use XmlSerializer for serlization/deserialization? if you didn’t sgen’ed your assemblies, then XmlSerializer will start csc.exe and compile some code to temporary folder.
Another option, is using CodeDom in C#. the code then will compile using csc.exe.