By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

error in "OnCreated" event of FileSystemWatcher class

P: n/a
Hi,
I am coding a Windows Service in which I am using the "OnCreated" event of
FileSystemWatcher class to do some processing when a new file is created in a
particular folder. However I have encountered the following issue in the
"OnCreated" event of FileSystemWatcher class.

Whenever a file is copied from a different folder (like network share) and
pasted to the monitoring folder and this copy & paste process takes time,
even before the file is fully pasted to the monitoring folder, the OnCreated
event of the FileSystemWatcher Class is treating the file as a new file. So
the code written to access the file to read the contents throws the below
error message
“The process cannot access the file because it is being used by another
process.“

Please let me know why the OnCreated event is recognizing a file as new even
before it has been fully pasted the folder. Also please let me know the best
recommended solution to this issue.

Regards,
Mahita
Jul 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
That is simply because the file is first created, then the contents of
the file is written to it.

The notification is created when the file has been created, but before
the contents is copied. For small files, the time from when the
notification is created until the event is handled in your program is
usually enough to copy the contents.

The issue can occur for any file that is copied, not only large files,
but it's more likely to occur the larger the file is.

Mahita wrote:
Hi,
I am coding a Windows Service in which I am using the "OnCreated" event of
FileSystemWatcher class to do some processing when a new file is created in a
particular folder. However I have encountered the following issue in the
"OnCreated" event of FileSystemWatcher class.

Whenever a file is copied from a different folder (like network share) and
pasted to the monitoring folder and this copy & paste process takes time,
even before the file is fully pasted to the monitoring folder, the OnCreated
event of the FileSystemWatcher Class is treating the file as a new file. So
the code written to access the file to read the contents throws the below
error message
“The process cannot access the file because it is being used by another
process.“

Please let me know why the OnCreated event is recognizing a file as new even
before it has been fully pasted the folder. Also please let me know the best
recommended solution to this issue.

Regards,
Mahita
Jul 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.