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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top