Мне нужно отправить список ошибок через 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
, чтобы остановить отправку данных??