-4

I am tasked with creating an app to monitor a folder for files to be processed.

I was wondering if there is anything new an exciting that I can use or should I just spin up a good old windows service?

John Doe
  • 3,053
  • 17
  • 48
  • 75
  • 2
    `FileSystemWatcher` comes to mind – KDecker Apr 28 '16 at 17:51
  • I think this is a pretty elegant solution. Eliminates the need for polling and since it's waiting for last write, you don't have to worry about catching various IO exceptions when other applications are writing the files. [Using FileSystemWatcher to Monitor a Directory](http://stackoverflow.com/questions/15017506/using-filesystemwatcher-to-monitor-a-directory) – Jake Apr 28 '16 at 17:52

1 Answers1

5

Nothing much better than the good, old FileSystemWatcher. Here is an example:

private void Watch()
{
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = path;
    watcher.NotifyFilter = NotifyFilters.LastWrite;
    watcher.Filter = "*.*";
    watcher.Changed += new FileSystemEventHandler(OnChanged);
    watcher.EnableRaisingEvents = true;
}

void OnChanged(object sender, FileSystemEventArgs e)
AGB
  • 2,230
  • 1
  • 14
  • 21
AutomationNation
  • 527
  • 1
  • 4
  • 10