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.
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();
}
sonyaPosted May 28, 2009, 2:08 PM
I am not using any threading.
Mike GoldPosted May 28, 2009, 1:53 PM
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) {}