networkstream read 方法跟 DataAvailable 引发的一个 System.IO.IOException 异常要怎么去避免?
哪位知道? private int ReadLine(string mail)
{
int reCode = 0;
string retMsg = String.Empty;
try
{
byte[] readbuffer = new byte[1024 * 2];
ns.ReadTimeout = TimeOut;
if (ns.CanRead)
{
do
{
ns.Read(readbuffer, 0, readbuffer.Length);
if (!string.IsNullOrEmpty(retMsg.Trim()))
{
try
{
reCode = Convert.ToInt32(retMsg.Trim().Substring(0, 3));
}
catch
{
reCode = 355;
}
}
}
while (ns.DataAvailable);
retMsg = System.Text.Encoding.ASCII.GetString(readbuffer);
AsyncText(retMsg);
}
}
catch (System.IO.IOException errs)
{
AsyncText(" IO操作异常,网络基础流关闭,但邮件可能已发送成功");
reCode = 355;
}
catch (ArgumentOutOfRangeException ers)
{
AsyncText("超时异常");
reCode = 355;
}
catch (Exception esc)
{
AsyncText("读取信息异常");
reCode = 355;
}
//操作遇到失败
if (reCode > 400)
{
WriteErrmail(mail);
}
return reCode;
}
哪位知道? private int ReadLine(string mail)
{
int reCode = 0;
string retMsg = String.Empty;
try
{
byte[] readbuffer = new byte[1024 * 2];
ns.ReadTimeout = TimeOut;
if (ns.CanRead)
{
do
{
ns.Read(readbuffer, 0, readbuffer.Length);
if (!string.IsNullOrEmpty(retMsg.Trim()))
{
try
{
reCode = Convert.ToInt32(retMsg.Trim().Substring(0, 3));
}
catch
{
reCode = 355;
}
}
}
while (ns.DataAvailable);
retMsg = System.Text.Encoding.ASCII.GetString(readbuffer);
AsyncText(retMsg);
}
}
catch (System.IO.IOException errs)
{
AsyncText(" IO操作异常,网络基础流关闭,但邮件可能已发送成功");
reCode = 355;
}
catch (ArgumentOutOfRangeException ers)
{
AsyncText("超时异常");
reCode = 355;
}
catch (Exception esc)
{
AsyncText("读取信息异常");
reCode = 355;
}
//操作遇到失败
if (reCode > 400)
{
WriteErrmail(mail);
}
return reCode;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货