By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

Question about FileSystemWatcher behavior

P: n/a
Hi,
I have a FileSystemWatcher object to monitor one certain folder on
server.

FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\MyFolder";
watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName |
NotifyFilters.Size;
watcher.Filter = "*.txt";
watcher.Created += new FileSystemEventHandler(watcher_Created);

// Begin watching.
watcher.EnableRaisingEvents = true;

The event is like
private void watcher_Created(object sender, FileSystemEventArgs e) {
// do something lengthy
}

My question is, under heavy situation, if the second file is thrown to this
folder before event handler finishes processing for the first file, will
event handler wait until first one finishes or it will kick out anyway?

Thanks for any suggestion!

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The FileSystemWatcher events are queued. You can test this behavior by
putting a Thread.Sleep(. . .) in the event handler, and you'll see that
the event handlers operate synchronously. If you have an
subdirectories in c:\MyFolder, note that since you are watching for
LastWrite, you will have an event to handle when any files inside the
subfolder changes because that subfolder's LastWrite time will change.

Note that there is a buffer that queues file changing events, so if
there are a lot of changes (hundreds), the buffere will overflow and
corrupt your watcher, and you'll have to recreate it. This isn't a
problem if you won't have hundreds of file changes in a short period of
time.

Best regards,
Jeffrey Palermo
Blog: http://www.jeffreypalermo.com

Nov 16 '05 #2

P: n/a
Thanks!

--
WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
"Jeffrey Palermo" <je************@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
The FileSystemWatcher events are queued. You can test this behavior by
putting a Thread.Sleep(. . .) in the event handler, and you'll see that
the event handlers operate synchronously. If you have an
subdirectories in c:\MyFolder, note that since you are watching for
LastWrite, you will have an event to handle when any files inside the
subfolder changes because that subfolder's LastWrite time will change.

Note that there is a buffer that queues file changing events, so if
there are a lot of changes (hundreds), the buffere will overflow and
corrupt your watcher, and you'll have to recreate it. This isn't a
problem if you won't have hundreds of file changes in a short period of
time.

Best regards,
Jeffrey Palermo
Blog: http://www.jeffreypalermo.com

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.