【发布时间】:2011-07-13 17:09:12
【问题描述】:
我需要使用此代码通过 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 中的连接是否断开以停止发送数据?
【问题讨论】:
标签: c# networking tcpclient