formclosing 이벤트의 텍스트 파일에 일부 문자열을 쓰려고합니다. 문제는 streamwriter가 아무 것도 쓰지 않는다는 것입니다. 빈 슬레이트 만 씁니다. 나는 2 개의 다른 텍스트 파일을 가지고 있는데 첫 번째 파일은 모든 그래프 데이터를 기록하고 두 번째 텍스트 파일은 내 응용 프로그램과 관련된 몇 가지 기본 설정을 기록합니다. 내 코드는 closing 이벤트 및 별도의 주력 방법 모두에 대해 다음과 같습니다양식 닫기 이벤트에서 텍스트 파일에 쓰기
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason.Equals(CloseReason.WindowsShutDown) || (e.CloseReason.Equals(CloseReason.UserClosing)))
{
if (MessageBox.Show("You are closing this application.\n\nAre you sure you wish to exit ?", "Warning: Not Submitted", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop) == DialogResult.Yes)
{
writeContents("Interrupted");
return;
}
else
e.Cancel = true;
}
}
private void writeContents(string status)
{
//---writes the graph data-----
TextWriter twBackupData = new StreamWriter("C://springTestBackupData.txt");
twBackupData.WriteLine("--Cycle#-- --TorqueLower-- --TorqueUpper--");
//writes the table of values in there, assume x and y are the same size arrays
for(int i = 0; i < x.Count; i++)
{
twBackupData.WriteLine(x[i] + " " + y_lower[i] + " " + y_upper[i]);
}
//---writes some of the preferences------
TextWriter twBackupDataInfo = new StreamWriter("C://springTestBackupInfo.txt");
twBackupDataInfo.WriteLine(status);
twBackupDataInfo.WriteLine(cycleCount.ToString());
twBackupDataInfo.WriteLine(section.ToString());
twBackupDataInfo.WriteLine(revsPerCycle.ToString());
twBackupDataInfo.WriteLine(preturns.ToString());
twBackupDataInfo.WriteLine(direction.ToString());
}
당신이 조언을 제공하거나 내가 대단히 감사하겠습니다 공백을 쓰고 왜 나를 찾을 수 있도록 할 수 있습니다. 고맙습니다!
다음 StreamWriter.Flush()와 StreamWriter.Close을 (시도) –
나는'.Close' 실제로뿐만 아니라'.Flush'를 호출 생각합니다. –