title: Read and Write to File at the same time
body: <p>for an application that uses a File as some sort of global storage for device reservations in a firm I need a way to read and write to a file (or lock a file, read from it, write to it, and unlock it). A little code snippet will shot what I mean:</p>
  
  <pre><code>FileStream in = new FileStream("storage.bin", FileMode.Open);
  //read the file
  in.Close();
  
  //!!!!!
  //here is the critical section since between reading and writing, there shouldnt
  //be a way for another process to access and lock the file, but there is the chance
  //because the in stream is closed
  //!!!!!
  FileStream out = new FileStream("storage.bin", FileMode.Create);
  //write data to file
  out.Close();
  </code></pre>
  
  <p>this should get something like this</p>
  
  <pre><code>LockFile("storage.bin");
  //read from it...
  //OVERwrite it....
  UnlockFile("storage.bin");
  </code></pre>
  
  <p>the method should be absolute safe, since the program should run on 2000 devices at the same time</p>