title: How to manually Lock a file for other applications
body: <p>I have spent quite some time figuring out how to do this but did not find any usefull solution.</p>
  
  <p>Here is what I want to do. I am generating a huge binary file in my application. The tricky thing is that, the process requires me to occasionally close the FileStream.
  The problem now is, that occasionally other applications (i.e. my virus scanner) are using this brief moment where the file is not locked anymore, to lock the file itself. or other applications like dropbox etc...</p>
  
  <p>The result is, that next time I need to open the file stream, it says that it is locked by another process. All this only happens very rarely but it is still annoying when it happens.
  And even if i still get the file access, I still don't want i.e. dropbox to upload this file until its done (which can take several minutes).</p>
  
  <p>What I would need is a possibility to manually lock a file so that my application can still open file streams on this file, but no other application can until I manually unlock it again.</p>
  
  <p>I picture something like this in pseudocode:</p>
  
  <pre><code> File.Lock(filepath);
  
   //... do something that opens and closes filestreams on this file
  
   File.Unlock(filepath);
  </code></pre>
  
  <p>Is there a way to do this? The solution "keep the file stream open" is not valid. I explicitly try to avoid that so please keep that in mind.</p>