The process cannot access the file '' because it is being used by another process

hellkitten

New Member
I have 2 programs, one is serializing XXXX.xml, and the other deserialize XXXX.xml.temp file.the 2 programs are individual and uses different threads that are happening every predefined interval.Following is the code that reads the xml.here i am getting the following exception:The process cannot access the file '' because it is being used by another process.\[code\] private void StartDiskFlushThread() { _flushThread = new Thread(ThreadProc); _flushThread.IsBackground = true; _flushThread.Start(); } private void ThreadProc() { try { while (_flushThread.IsAlive) { FlushStepsToFile(); Thread.Sleep(_flushInterval); } } catch (Exception ex) { Console.WriteLine(ex); Log.Error("ThreadProc failed", ex); } } private void FlushStepsToFile() { try { SerializeSteps(1); } catch (Exception ex) { Log.Error("Failed to flush steps to disk, retrying", ex); Thread.Sleep(1000); SerializeSteps(2); } } private void SerializeSteps(int trycount) { XmlSerializer serializer = new XmlSerializer(typeof(DetailedSteps)); try { using (TextWriter textWriter = new StreamWriter(_targetFileLocation)) { serializer.Serialize(textWriter, _detailedSteps); } } catch (Exception ex) { Log.ErrorFormat("SerializeSteps method failed. try #{0}. Error:{1}", trycount, ex); } }\[/code\]As for the code that reads the xml.The program is also a thread that copies the XXXX.xml to XXXX.xml.temp and than reads the temp file.\[code\] private void CopyPartialLog() { try { File.Copy(ReportFile, DestReportFile, true); } catch (Exception ex) { Log.Error("CopyPartialLog failed", ex); } }\[/code\]i have no exceptions there because i am reading different file: XXXX.xml.tempfollowing is the exception i am getting from the first program that writes the xml:\[quote\] 7077846 [SerializeSteps method failed. try #1. Error:System.IO.IOException: The process cannot access the file 'xxxx.xml' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)\[/quote\]the exception i am getting is hanging my writer thread and i don't understand why.what do you suggest? how can i resolve it?
 
Back
Top