title: C# - Blocking a folder from being changed while processing
body: <p>I have a single-threaded program that processes folders and files in a source directory.  Is there a way to block a folder, with files in it, within my source directory from being modified by other processes while my program is working on it?  I'm thinking something along the lines of placing some kind of exclusive lock on the folder itself, so only my program's process can use it.</p>
  
  <p>NOTE:</p>
  
  <p>I do not want to block the root source directory itself, just whatever folder(s), in the top level of that directory, I might be processing at any particular moment.  I still want to be able to allow outside processes to add folders to the source directory, while I'm processing other folders.</p>
  
  <p>UPDATE:</p>
  
  <p>@Yuri - Yes this is a Windows program, a Windows Service application to be exact.</p>
  
  <p>Part of what makes this both challenging and necessary is that I need to recreate the structure of whatever folder(s) I'm processing, in the source directory, in a separate destination directory.  So I can't have a any other process modifying the folder(s) and File(s) while my program is working with them.</p>