473,386 Members | 1,775 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,386 software developers and data experts.

FileSystemWatcher: problems with event-catching

Hi,

we have some problems with the following situation:
A remote application A writes files to a directory monitored by a
FileSystemWatcher-instance in application B. A creates the file
with the initial ending "COPY_IN_PROGRESS" and only after
successful copying the file gets renamed to its final ending
"TO_DO". The FileSystemWatcher of B is set to react on the
rename-event and upon recognizing an event some processing
is triggered.
Now the problem is that obviously the event is raised and also
recognized, however the renamed file seems to not yet exist
within the filesystem: the given RenamedEventArgs contain the
new filename, however a File.Exists on this filename, executed
first within the OnEvent-method, returns with false.
Though, if some trace messages are inserted before the File.Exists
everything is working fine, so it seems that there might be some
sort of timing problem. Is it possible that the rename event is
raised before completion of the file system update.
Does anyone know something about this problem or has a solution
ready? (inserting some delay wouldn't be a proper solution; a
completely event-driven solution is preferred)

Thanks in advance
Andreas

Nov 15 '05 #1
1 4488
The Rename and create events of the filesystemwatcher both are quite
eager -- that is, you get the events early, and may not be able to yet
access the file in question.

For any application / service I have written using the FSW, I've normally
done the following
1) Upon getting the event, spawn a "processing thread" and start it up
2) in the processing thread, try to access the file repeatedly until
sucessful (sleeping a bit in-between tries)
3) Let the processing thread completely process the file, the notify the
application thread that the contents are ready.

"Andreas" <Am*******@gmx.net> wrote in message
news:1075727236.354573@nbgm66x...
Hi,

we have some problems with the following situation:
A remote application A writes files to a directory monitored by a
FileSystemWatcher-instance in application B. A creates the file
with the initial ending "COPY_IN_PROGRESS" and only after
successful copying the file gets renamed to its final ending
"TO_DO". The FileSystemWatcher of B is set to react on the
rename-event and upon recognizing an event some processing
is triggered.
Now the problem is that obviously the event is raised and also
recognized, however the renamed file seems to not yet exist
within the filesystem: the given RenamedEventArgs contain the
new filename, however a File.Exists on this filename, executed
first within the OnEvent-method, returns with false.
Though, if some trace messages are inserted before the File.Exists
everything is working fine, so it seems that there might be some
sort of timing problem. Is it possible that the rename event is
raised before completion of the file system update.
Does anyone know something about this problem or has a solution
ready? (inserting some delay wouldn't be a proper solution; a
completely event-driven solution is preferred)

Thanks in advance
Andreas

Nov 15 '05 #2

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: Lloyd Sheen | last post by:
I have created a FileSystemWatcher application that monitors a set of folder for changes. This works well as a windows app. I have copied the code from the windows app to a windows service and...
1
by: Troy Murphy | last post by:
How do I prevent the FileSystemWatcher event to keep firing while the file is being created? When copying a file to the watched folder, the event fires a dozen or more times! Also, the...
3
by: Craig Thompson | last post by:
I've attempted to write a windows service that creates one FileSystemWatcher for each entry in a XML config file. Everything start perfrectly and runs as I expect for about 5 minutes and then...
2
by: Bonnett | last post by:
I have made a simple console application that creates a webpage from my playlist, then uploads it to my webhost. I decided to convert it to a windows service and use the FileSystemWatcher to...
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 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...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
2
by: kmcnet | last post by:
Hello Everyone and thanks for your help in advance. I have been battling a problem for nearly a month with the FileSystemWatcher component. Basically, what I am trying to do it to monitor three...
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: 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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?
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,...

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.