Assume we have 3 processes, they write to a specific file by order, in some cases when a process wants to write to the file the process closed (In middle of Writing), so access to file for another 2 processes is in trouble, I add a server process that control order of processes and when a process closed there is an event raised, so how can I release sources (file access) in this event when a process closed. Something like File.Release(FilePath);
Edit:
Write to File as Following:
try { if(!File.Exists(FilePath)) throw new Exception("File does not Exist."); bool Clear = false; using(StreamReader sr = new StreamReader(FilePath)) { if(sr.ReadToEnd().Length > 1200) Clear = true; } if(Clear) using(StreamWriter sw = new StreamWriter(FilePath, false)) { sw.WriteLine(Text); sw.Flush(); } else using(StreamWriter sw = new StreamWriter(FilePath, true)) { sw.WriteLine(Text); sw.Flush(); } } catch(Exception ex) {}
usingblock).sw.Close()orsw.Dispose()if you're usingusingblocks.usingblock will do them for you.