Opinion on how best to wait for a file

  • Thread starter Thread starter john bailo
  • Start date Start date
J

john bailo

I'm writing a program to monitor the operation of a process.

Part of the process involves trigging a method,
then waiting for the creation of a flag file. I
want my code to pause at that point.

How would you recomment waiting and monitoring.
I can think of two ways:

0. Start a timer.
1. Raise an event to check for File.Exists("")
2. If File.Exists then Timer.Enabled=false.


Or

Do a while loop, with while(File.Exists())

What do you guys recommend?
 
You have the added option of using a FileSystemWatcher and receive an event
when stuff happens in 'Watched' folders. Details are in MSDN.
 
The filesystemwatcher is known to have issues because of the underlying OS
which doesn't always notify the listener. Proceed with caution.
 
The Filesystemwatcher object is designed to do this, and will raise an event
when a file is created / modified / deleted within a specicified directory.
Get your code to start the watcher, then call the code you need to run once
the file's created in the handler for the appropriate event.

--

Regards

Tim Stephenson MCSD.NET
Charted MCAD & MCSD.NET Early Achiever
 
Back
Top