I have a program that I use to write data to an excel file.... and at the same time I use an excel file to import data from the first excel file using (import data) tool.
This is part of the program code :
private void Log(string pText)
{
//textBox1.AppendText(pText + "\r\n"); // does not put cr lf, why?
this.BeginInvoke(new MethodInvoker(delegate () {
textBox1.AppendText(pText);
textBox1.AppendText("\n");
}));
}
private void LogStatus(string pText)
{
textBox1.AppendText(pText + "\t");
textBox1.AppendText("\n");
}
StreamWriter theString = new StreamWriter(FileName + ".csv", true);
theString.WriteLine(DateTime.Now + dataToSave + "\t\n");
theString.Close();
my problem is when i start to debuge my program in Visual C# 2008
it will work will and start to write data to the first excel file....then during the debug process
i want to import data from the first excel file to the second one using import data(it's important for me to do that in real time i cant delay the import process)
the debuging process stopped and the visual C# 2008 higlight this line of the code
theString.Close();
and a message popup to me said
The process cannot access the file because another process has locked a portion of the file.
any help in overcome this problem plz
and thanks