FileSystemWatcher moniters file with error process cannot access f

G

Guest

I created a windows service using FileSystemWatcher to moniter a folder for
file drops. The service uses FileStream and StreamReader to read and process
the file. After it is done, the file is copied to a different location and
deleted in the original folder.

If files coming in in short intervals (under sub-second) on XP OS, there is
an error occured occassionally with the follow message:
System.IO.IOException: The process cannot access the file, because it is
being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
Boolean bFromProxy).

However, on W2K OS, the error could happen even with 5 sec interval between
file droppings.

I am not sure if this is a load related issue especially on the W2K box.
Any suggestions and comments would be appreciated. My environment is XP with
Framework 1.1 as Dev box and the Production Server is W2K with Framework 1.1.
Both environment has the 1.1 SP1 installed.


Thank you
 
?

=?iso-8859-1?Q?Lasse=20V=e5gs=e6ther=20Karlsen?=

I created a windows service using FileSystemWatcher to moniter a
folder for file drops. The service uses FileStream and StreamReader
to read and process the file. After it is done, the file is copied to
a different location and deleted in the original folder.

If files coming in in short intervals (under sub-second) on XP OS,
there is
an error occured occassionally with the follow message:
System.IO.IOException: The process cannot access the file, because it
is
being used by another process.

What kind of filtering do you have? only changes to the files? new files?
etc.
Do you retry if the file is in use? Your code could be triggered because
the application created the file and is still writing to it.
 
G

Guest

The NotifyFilters = NotifyFilters.FileName;

I am not sure what you mean of "Do you retry if the file is in use?". And
this seems to be the problem as the application is still reading/writing
while a new file is dumped in the monitoring folder.

Thank you.

ZW
 
G

Guest

Need to check the existance and accessibility before process the file as the
FSW event is triigged when the file is still creating and not accessible yet.

See posting FileSystemWatcher + Monitor Reads/Opens on 1/16/06 for reference.
 
G

gman

It sounds like your trying to access the file before it has completed
writing to the disk.
 
G

Guest

Not me, the FileSystemWatcher Class is trying to access the file before it
has completed writing to the disk. Microsoft offered a greate class to
watch for the files, but programmers have to handle the issue not accessing
the file before it has completed writing to the disk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top