Hi,
Can someone please help me.
I am getting error: The process cannot access the file 'c:\reports\PaymentDetailReport.xml' because it is being used by another process. in following function.
This method is suppose to be called couple of times. but at second time, it throws the error. I have even closed tw.
TypeScript
private void saveReport(string reportName, string data)
{
if (reportName == "PaymentReport")
{
StreamWriter tw = new StreamWriter(_documentName);
tw.WriteLine(data, true);
StreamWriter masterPSDR = File.AppendText("C:\\reports\\masterPSDR.xml");
masterPSDR.WriteLine(data, true);
tw.Close();
masterPSDR.Close();
}
Mike GoldRank #50 · 30.6K pointsPosted May 28, 2009, 9:53 AM EDT
you may have a threading issue. if the file is accessed before it is closed, it will throw the error you are getting. Make sure you lock the area of the thread lock(this) {}
sonya2 pointsPosted May 28, 2009, 10:08 AM EDT
I am not using any threading.