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

error in "OnCreated" event of FileSystemWatcher class

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
1 2550
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nicolas | last post by:
How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot. ******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher(); public delegate void...
9
by: Vai2000 | last post by:
Hi All, Here's a situation, I am trying to process some large Files via a Win Svc using FileMonitor. During the test process I tried copy and pasting a file in a folder and got an error saying...
6
by: acool | last post by:
I managed to get my VB.NET service installed. Now I can't get it to do anything. Tell me how do you debug smething like this if you have to manually install the assembly to run it? the same code...
7
by: Raj Wall | last post by:
I have threads with event handlers to watch for new files placed in directories. The handler has a Using { ... } block to process the file which is then deleted. In testing I can drag/drop FileA...
1
by: Rocky | last post by:
I have created a windows service using vb.net which uses a filesystemwatcher to monitoe files in a specifc directory, if images are added to the directory they are resized and saved in a remote...
1
by: john | last post by:
SubmitChanges() works on some tables everytime & not at all on others and the only thing I see different is that it is not creating any code like this on the one that does not works, the one that...
3
by: Andrus | last post by:
Two assemblies both referenced by application contain same class (created by script): namespace Script { public class Class1 { } } Compiling application
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:
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.