Question : Signal/Alert when a file has been placed/created in a directory

Hi.

I'm looking for a more efficient way to alert/signal when a file has been created/placed in a directory. The obvious choice is:

bool exists=false
while(!exists)
{
  if File.Exists("my file")
    exists = true;
  else
    Thread.Sleep(10);
}

Is there a more efficient way to do this, perhaps a signal we can trap when activity occurs on a specific directory?

Thanks.

Answer : Signal/Alert when a file has been placed/created in a directory

Use a System.IO.FileSystemWatcher
This lets you know when various activities happen.  It is confusing to deduce what actually happened, but you can set a filter on the watcher to just watch for activity on that file and then check for existence when triggered.
Random Solutions  
 
programming4us programming4us