title: Releasing access to files
body: <p>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 <code>File.Release(FilePath);</code> </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Write to File as Following:</p>
  
  <pre><code>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 &gt; 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) {}
  </code></pre>