473,385 Members | 2,028 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,385 software developers and data experts.

FileSystemWatcher Events - Threads or not?

Hi,
I want to use the FileSystemWatcher in a Windows Service. I read an article,
where the author created the FileSystemWatcher object in a seperate thread
and when the event is fired, he started a working thread for processing the
file, created a new FileSystemWatcher (as he said for real time processing),
and then called the join method for the first thread.

I can't really see the sence in this. Aren't the events of the
FileSystemWatcher created in seperate threads? (As it works with asynchronus
Sockets, I think)

Because if so, then the seperate thread for the FileSystemWatcher and the
creation of a new one for the new files would be complete nonsense.

I hope someone can clear this. I need to know how FileSystemWatcher works
and if it uses threads or not.

greetings

Florian
Nov 17 '05 #1
3 14202
"Stampede" wrote:
Hi,
I want to use the FileSystemWatcher in a Windows Service. I read an article,
where the author created the FileSystemWatcher object in a seperate thread
and when the event is fired, he started a working thread for processing the
file, created a new FileSystemWatcher (as he said for real time processing),
and then called the join method for the first thread.

I can't really see the sence in this. Aren't the events of the
FileSystemWatcher created in seperate threads? (As it works with asynchronus
Sockets, I think)

Because if so, then the seperate thread for the FileSystemWatcher and the
creation of a new one for the new files would be complete nonsense.

I hope someone can clear this. I need to know how FileSystemWatcher works
and if it uses threads or not.

greetings
Florian


Hi Florian,

All events triggered by a FileSystemWatcher instance, are called on a thread
pool thread.

If your response to the event is a lengthy operation, you may consider
handling the event further on a seperate thread because the following
registered handlers aren't called until yours completes.

Although I don't know for sure, it may even be that other events triggered
by one file operation aren't executed until all previous events have
completed (one file operation may trigger several FileSystemWatcher events).

Also, it is possible that a FileSystemWatcher's event buffer overflows (the
buffer does not grow). So if your handling would keep other events from being
fired then this could result in buffer overflow so events would be lost.

So basically, if you don't do a lot when handling such an event, that's
fine. If however handling such an event is a lenghty operation, you may want
to handle the event on a seperate (worker) thread.

Hope this helps,
--
Tom Tempelaere.

Nov 17 '05 #2
Hi again,

Hints and tips here:

http://www.knowdotnet.com/articles/fwrecovery.html
http://weblogs.asp.net/ashben/archiv.../14/31773.aspx

Or search the net for more

Cheers,
--
Tom Tempelaere.
"Stampede" wrote:
Hi,
I want to use the FileSystemWatcher in a Windows Service. I read an article,
where the author created the FileSystemWatcher object in a seperate thread
and when the event is fired, he started a working thread for processing the
file, created a new FileSystemWatcher (as he said for real time processing),
and then called the join method for the first thread.

I can't really see the sence in this. Aren't the events of the
FileSystemWatcher created in seperate threads? (As it works with asynchronus
Sockets, I think)

Because if so, then the seperate thread for the FileSystemWatcher and the
creation of a new one for the new files would be complete nonsense.

I hope someone can clear this. I need to know how FileSystemWatcher works
and if it uses threads or not.

greetings

Florian

Nov 17 '05 #3
Thanks a lot for that answer, I just thought that noone might really know how
this class does its work!

greetings

Florian

"TT (Tom Tempelaere)" wrote:
"Stampede" wrote:
Hi,
I want to use the FileSystemWatcher in a Windows Service. I read an article,
where the author created the FileSystemWatcher object in a seperate thread
and when the event is fired, he started a working thread for processing the
file, created a new FileSystemWatcher (as he said for real time processing),
and then called the join method for the first thread.

I can't really see the sence in this. Aren't the events of the
FileSystemWatcher created in seperate threads? (As it works with asynchronus
Sockets, I think)

Because if so, then the seperate thread for the FileSystemWatcher and the
creation of a new one for the new files would be complete nonsense.

I hope someone can clear this. I need to know how FileSystemWatcher works
and if it uses threads or not.

greetings
Florian


Hi Florian,

All events triggered by a FileSystemWatcher instance, are called on a thread
pool thread.

If your response to the event is a lengthy operation, you may consider
handling the event further on a seperate thread because the following
registered handlers aren't called until yours completes.

Although I don't know for sure, it may even be that other events triggered
by one file operation aren't executed until all previous events have
completed (one file operation may trigger several FileSystemWatcher events).

Also, it is possible that a FileSystemWatcher's event buffer overflows (the
buffer does not grow). So if your handling would keep other events from being
fired then this could result in buffer overflow so events would be lost.

So basically, if you don't do a lot when handling such an event, that's
fine. If however handling such an event is a lenghty operation, you may want
to handle the event on a seperate (worker) thread.

Hope this helps,
--
Tom Tempelaere.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Josh Usovsky | last post by:
I'm setting up a watched folder using FileSystemWatcher. When I drop a small file into the watched folder, I can respond to a .Created event and process the file with other code. However, if I try...
0
by: cxw0106 | last post by:
Hello, I have some weird problem with the FileSystemWatcher. I have developed an application that monitors a network directory for file changes of a certain file type. The program runs well for...
3
by: Michael Stanbrook | last post by:
I'm using the FileSystemWatcher to looks for new files arriving in a directory. Files are coming in via FTP and tend to be larger is size (> 1MB at least). I would like to fire an event once 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: Stampede | last post by:
Hi, I write an application which waits for incomming files in a specified directory. I thought, that using the FileSystemWatcher would be the best, as it does exactly what I need. But now I have...
8
by: Pedro C. Valenzuela | last post by:
Hello, Does anyone know how a File System Watcher windows control works to detect file changes accross the network to a remote machine? I am trying to watch for new files in 30 different...
5
by: Philip Wagenaar | last post by:
I have a Windows Form application that monitors a directory using the System.IO.FileSystemWatcher. On the event created I run a sub that sends an xml file over http to a service. When I copy...
12
by: ljh | last post by:
Has anyone else noticed that the FileSystemWatcher raises the changed event twice when a file is changed? Do you have any idea why this is the case?
1
by: teslar91 | last post by:
I've been learning VB.NET for the past few weeks. One of the problems I've run into is difficulties updating controls in events from certain components, such as the FileSystemWatcher, that raise...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.