디버그 용 콘솔을 시작할 수있는 Windows Forms 앱이 있습니다. 앱에서 메뉴를 클릭하면 CSV 파일을 읽고 콘솔에 씁니다. 이 작업을 수행하는 함수는 다음과 같습니다.C# : Windows App CSV 파일 읽기 및 콘솔에 쓰기 문제
protected void menuRead_Click(object sender, EventArgs e)
{
// ... functionality to load CSV files
System.IO.Stream inputDataFile = null;
OpenFileDialog fd = new OpenFileDialog();
fd.InitialDirectory = "c:\\";
fd.Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*";
fd.FilterIndex = 1;
fd.RestoreDirectory = true;
if (fd.ShowDialog() == DialogResult.OK)
{
try
{
if ((inputDataFile = fd.OpenFile()) != null)
{
inputData_exists = true;
// ... read input data from CSV file
using (CsvFileReader reader = new CsvFileReader(inputDataFile))
{
CsvRow row = new CsvRow();
while (reader.ReadRow(row))
{
foreach (string s in row)
{
Console.Write(s);
Console.Write(" ");
}
Console.WriteLine();
}
// ... close the input data stream
inputDataFile.Close();
}
}
}
catch (Exception err)
{
//Inform the user if can't read the file
MessageBox.Show(err.Message);
}
}
}
모두는 다음을 제외하고 잘 작동 : CSV 파일의 코드 1200 라인을 가지고있다. 이 코드가 실행되면 OpenFileDialog() 창이 부분적으로 닫히고 CSV 파일 내용이 콘솔 창에 기록되기 시작합니다. 그래서 콘솔 창에 데이터를 쓰는 것을 볼 수 있습니다. 대화 상자 창에 작은 사각형 부분이 있습니다. 데이터가 콘솔에 기록되기 전에 대화 상자를 닫을 수있는 방법이 있습니까? 콘솔과 통신하기 위해 새 스레드를 열어야합니까? 어떤 조언이나 도움 woulf 크게 감상 할 수 있습니다. 고맙습니다.
이렇게하면 각 행을 읽은 후 강제로 다시 칠합니다. 이것은 자원 낭비와 같지만 정보를위한 행크스처럼 보인다. – Zeos6
어쩌면 시도해 볼 수 있습니다 fd.Invalidate(); –
@ Zeos6 : 아니요. 읽기 루프가 그 아래에서 시작됩니다. – ChrisWue