473,848 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileSystemWatch er Events - Threads or not?

Hi,
I want to use the FileSystemWatch er in a Windows Service. I read an article,
where the author created the FileSystemWatch er object in a seperate thread
and when the event is fired, he started a working thread for processing the
file, created a new FileSystemWatch er (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
FileSystemWatch er created in seperate threads? (As it works with asynchronus
Sockets, I think)

Because if so, then the seperate thread for the FileSystemWatch er 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 FileSystemWatch er works
and if it uses threads or not.

greetings

Florian
Nov 17 '05 #1
3 14315
"Stampede" wrote:
Hi,
I want to use the FileSystemWatch er in a Windows Service. I read an article,
where the author created the FileSystemWatch er object in a seperate thread
and when the event is fired, he started a working thread for processing the
file, created a new FileSystemWatch er (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
FileSystemWatch er created in seperate threads? (As it works with asynchronus
Sockets, I think)

Because if so, then the seperate thread for the FileSystemWatch er 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 FileSystemWatch er works
and if it uses threads or not.

greetings
Florian


Hi Florian,

All events triggered by a FileSystemWatch er 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 FileSystemWatch er events).

Also, it is possible that a FileSystemWatch er'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 FileSystemWatch er in a Windows Service. I read an article,
where the author created the FileSystemWatch er object in a seperate thread
and when the event is fired, he started a working thread for processing the
file, created a new FileSystemWatch er (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
FileSystemWatch er created in seperate threads? (As it works with asynchronus
Sockets, I think)

Because if so, then the seperate thread for the FileSystemWatch er 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 FileSystemWatch er 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 FileSystemWatch er in a Windows Service. I read an article,
where the author created the FileSystemWatch er object in a seperate thread
and when the event is fired, he started a working thread for processing the
file, created a new FileSystemWatch er (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
FileSystemWatch er created in seperate threads? (As it works with asynchronus
Sockets, I think)

Because if so, then the seperate thread for the FileSystemWatch er 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 FileSystemWatch er works
and if it uses threads or not.

greetings
Florian


Hi Florian,

All events triggered by a FileSystemWatch er 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 FileSystemWatch er events).

Also, it is possible that a FileSystemWatch er'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
9124
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 copying a large file into the watched folder, the .Created event is fired off immediately and not when the file is finished copying. I have tried waiting for a certain number of .Changed events to be fired after the initial .Created event, and...
0
3012
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 a week. Then suddenly the monitored network server starts to behave crazily. It sends to my Sync Server dozens of replicated file change events. Say one file was changed two days ago, but the monitored server still keeps sending me many many...
3
9485
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 file is completely written. I understand there is nothing "exactly" like that due to how the OS filesystem works, so I am looking for a workaround. I am currently attempting to open the "new" file in
1
4631
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 does not trigger the event - all I have to do is to restart the service. I kind of suspect the reason is when the target matchine where monitored drive is on gets rebooted, the filesystemwatcher lost its "monioring" capability, is that true? if...
3
4606
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 a problem: I wonna get shure, that really all files are processed and I need to be shure, that no file is processed twice. If my application is started while there are already files in the directory (which is realistic, as the application could...
8
654
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 folders in a remote machine that has around 1000 folders. I dont know if it's wise to put one single watcher for the whole machine, or 30 different watchers because i dont know if the watchers take up bandwidth or processing power.
5
5154
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 7000 files in the directory to be monitored only 123 are sent to the service. What might be going wrong?
12
7464
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
2367
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 their events in different threads. I found plenty of examples on the Web of how to "detangle" the threads, using Delegate functions, .InvokeRequired, and .Invoke. But all of these examples demonstrated how to do it on a single form. I wanted...
0
9893
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10722
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10348
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9500
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4137
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.