我正在使用StreamReader
,但如果尝试使用两个StreamReader
-objects 从同一流中读取,我会收到错误消息 I can't read from dispose object (reader3.ReadLine)
。由于我没有处理任何对象,我做错了什么?
Stream responseStream2;
FtpWebResponse ftpResponse2;
string casefile = CNCElement.ID_CASE_TEST_FILE;
string casepath;
if (FileManager.PathCombine(result, lock_root_folder, casefile, out casepath) == false)
return false;
if (fm.DownloadFtp(result, casepath, out responseStream2, out ftpResponse2) == false)
return false;
StreamReader reader2 = new StreamReader(responseStream2);
StreamReader reader3 = new StreamReader(responseStream2);
byte[] contents=null;
//if cycle is not present update case file
//if cycle is present, case file is already correct
if (reader2.ReadToEnd().Contains(cycle) == false)
{
byte seekcase = CNCElement.ID_CASE.Value;
int casecount = 1;
string line;
using (MemoryStream ms = new MemoryStream())
{
while ((line = reader3.ReadLine()) != null
|| casecount <= seekcase)
{
if (line.Contains("\"\"") == true)
{
if (casecount == seekcase)
line = line.Replace("\"\"", "\"" + cycle + "\"");
}
byte[] app = StrToByteArray(line);
ms.Write(app, 0, line.Length);
contents = ms.ToArray();
}
}
}
if (reader2 != null)
reader2.Close();
if (ftpResponse2 != null)
ftpResponse2.Close();