473,394 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Question about FileSystemWatcher behavior

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
2 1435
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jet Leung | last post by:
Hi all, I had made a program to watching files in my directory. I had used a instance of FileSystemWatcher to do my work.And I had add some events of the FileSystemWatcher , for example onChange,...
2
by: Jack David | last post by:
Using the code below I am able to monitor a single directory for a new file and then kick-off a process to deal with the file. The question is??? How would I modify this code to be able to monitor...
2
by: Sagaert Johan | last post by:
Hi I use the FileSystemWatcher to detect creation of files. As soon as the event fires i do something with the file, but i sometimes get a sharing error. I noticed that when the event fires the...
1
by: John Lee | last post by:
Hi, I developed a filewatcher service to monitor file creation on a network drive - 90% time it works fine and from time to time I found out that the newly created file on that network drive...
3
by: Krish | last post by:
Hello Gurus, Pardon me for asking dumb question... I wrote small csharp program to watch a folder for any created text file... When i try to run through debugger and stop after "...
1
by: dinny | last post by:
Question about FileSystemWatcher: How can I determine if a delete notification was a file or a directory. I was using the DirectoryInfo.exists method to determine if I am receiving file or...
7
by: John D'oh | last post by:
Hello, I have been going through the MSDN Walkthrough: Creating a Windows Forms Control That Takes Advantage of Visual Studio Design-Time Features. Everything was going fine and I was able to...
3
by: =?Utf-8?B?TWljaGFlbE4=?= | last post by:
I am designing a multi-threaded application which responds to a FileSystemWatcher events. Depending on the file created, I need to either archive the file to a specific directory, or process the...
7
by: =?Utf-8?B?Tmljaw==?= | last post by:
Hello, I've got a FileSystemWatcher object setup to check for new files in a folder. I've never done much with threading, but I think I mght need to here. When I find a new file there are times...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.