2
我需要發送錯誤槽TcpClient的列表與此代碼如何檢測斷開完成發送數據槽的TcpClient
private bool TryConn(out TcpClient cliente)
{
var client = new TcpClient();
try
{
client.Connect(IpAddress, PortNumber);
cliente = client;
return true;
}
catch
{
cliente = null;
return false;
}
}
public void ProcesssRecovery()
{
//NonMassiveErrorerror= new NonMassiveError();
TcpClient client;
//get error
IEnumerable<NonMassiveError> errorNotNotified = GetUncheckedNonMassiveError();
//check if lista is not empty
if (errorNotNotified .Count() >0)
{
// check connection
if (TryConn(out client))
{
foreach (NonMassiveError error in errorNotNotified)
{ // sending error<--how detect conn stops
SendMessage(error, client, "asin" , "");
error.Save();
}
}
}
//stop thread 10mins
else
{
Thread.Sleep(TimeSpan.FromMinutes(10));
}
}
}
如何檢查,如果連接在foreach
落下停止發送數據?