텍스트를 내 txt 파일에 쓰려고합니다. 첫 번째 후 것은닫힌 TextWriter에 쓸 수 없습니다.
이이
내 목록은 브라우저가 열리는 링크가 포함되어 폐쇄 TextWriter에 쓸 수 없습니다 오류와 응용 프로그램 충돌을 작성하고 나는 로그처럼 (txt 파일에 모두 저장하려면).
내 코드 :
FileStream fs = new FileStream(
"c:\\linksLog.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
for (int i = 0; i < linksList.Count; i++)
{
try
{
System.Diagnostics.Process.Start(browserType, linksList[i]);
}
catch (Exception) { }
using (sw)
{
sw.WriteLine(linksList[i]);
sw.Close();
}
Thread.Sleep((int)delayTime);
if (!cbNewtab.Checked)
{
try
{
foreach (Process process in Process.GetProcesses())
{
if (process.ProcessName == getProcesses)
{
process.Kill();
}
}
}
catch (Exception) { }
}
}
사용을 마칠 때까지 StreamWriter (sw)를 닫지 마십시오. –
스트림을 올바르게 처리하려면 "사용"을 사용하십시오. – Bahamut