title: C# - locking in threads with mixed file and folder usage (thread safety)
body: <p>I wanted to ask if there is a special mechanism in C# or .net which can do the following:</p>
  
  <p>I have an multi threading application and I want to prevent threads doing something on the same file/folder. like the <code>lock(Object obj)</code> command it should block if an other thread is changing something on this file or folder or a sub folder.</p>
  
  <p>For example:<br />
  All threads starting at the same time (ok pseudo same time ;) ).<br />
  Thread A: uses folder1\folder2\file.txt and should lock it with an mechanism.<br />
  Thread B: uses folder1\file2.txt and should open another lock<br />
  Thread C: wants to rename folder1 and should be blocked as long as Thread A and Thread B releases the lock.<br />
  Thread D: renames folder3 and opens a lock wich blocks nothing.<br />
  Just an example what I'd like to see...</p>
  
  <p>It should be possible to have unlimited hierachical dependencies. I know there are some mechanisms for supporting file locking and maybe there is something to also lock folders with sub folders and prevent parent changes. If there is nothing then I have to implement it on my own.</p>