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

System.IO.FileSystemWatcher

System.IO.FileSystemWatcher

When a user copies and pastes a file from one directory to a directory that is monitored
by the FileSystemWatcher, the FileSystemWatcher executes twice, once for a CREATED file
event and once for a CHANGED file event.

I think I understand why. First the monitored file is created and then contents are
inserted into it. (Although the file datetime remains the same.)

This is not what I require. If there is a new file created in a monitored directoy, I
only want TRUELY CREATED event raised, not the default of CREATED event raised & CHANGED
event raised.

Is there anyway I can turn-off the second event (CHANGED event raise) ?

Thanks
Nov 6 '08 #1
2 3462
Hi this is a bug from Microsoft in this Obj

''' <remarks>Implementing a trick to stop double call from the onChange
FileSystemWatcher event bug</remarks>
Protected Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
Try

If lastChange <>
TimeSpan.FromTicks(Now.Ticks).TotalMilliseconds Then
'DO YOUR STUFF HERE
End If

lastChange =
TimeSpan.FromTicks(Now.Ticks).TotalMilliseconds

Catch ex As Exception
errorHandler(ex, Me.GetType.ToString & ".onChanged")

Finally
End Try

End Sub

Hope this help

Nicolas

"John Talli" wrote:
System.IO.FileSystemWatcher

When a user copies and pastes a file from one directory to a directory that is monitored
by the FileSystemWatcher, the FileSystemWatcher executes twice, once for a CREATED file
event and once for a CHANGED file event.

I think I understand why. First the monitored file is created and then contents are
inserted into it. (Although the file datetime remains the same.)

This is not what I require. If there is a new file created in a monitored directoy, I
only want TRUELY CREATED event raised, not the default of CREATED event raised & CHANGED
event raised.

Is there anyway I can turn-off the second event (CHANGED event raise) ?

Thanks

Nov 6 '08 #2
Thanks!!! I'll play with this and let everyone know the outcome. This double call is
an interesting feature from MS.
"Nicolas" <Ni*****@discussions.microsoft.comwrote in message
news:87**********************************@microsof t.com...
Hi this is a bug from Microsoft in this Obj

''' <remarks>Implementing a trick to stop double call from the onChange
FileSystemWatcher event bug</remarks>
Protected Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
Try

If lastChange <>
TimeSpan.FromTicks(Now.Ticks).TotalMilliseconds Then
'DO YOUR STUFF HERE
End If

lastChange =
TimeSpan.FromTicks(Now.Ticks).TotalMilliseconds

Catch ex As Exception
errorHandler(ex, Me.GetType.ToString & ".onChanged")

Finally
End Try

End Sub

Hope this help

Nicolas

"John Talli" wrote:
>System.IO.FileSystemWatcher

When a user copies and pastes a file from one directory to a directory that is
monitored
by the FileSystemWatcher, the FileSystemWatcher executes twice, once for a CREATED
file
event and once for a CHANGED file event.

I think I understand why. First the monitored file is created and then contents are
inserted into it. (Although the file datetime remains the same.)

This is not what I require. If there is a new file created in a monitored directoy,
I
only want TRUELY CREATED event raised, not the default of CREATED event raised &
CHANGED
event raised.

Is there anyway I can turn-off the second event (CHANGED event raise) ?

Thanks

Nov 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Allen Anderson | last post by:
I'm trying to figure out a way to catch when a file has been written to a directory. I currently have it where I can catch when the file begins writing, but this isn't helpful as I need to know...
2
by: Jack David | last post by:
Using the code below I am able to monitor a single directory for a new file and then kick-off a process to deal with the file. The question is??? How would I modify this code to be able to monitor...
2
by: Nony Buz | last post by:
My objective is simply: Notify a form when a image file has been created in a directory. First there is a basic interface for the callback function: public interface INewImageNotify { void...
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...
11
by: jcrouse | last post by:
From what I can tell on Microsoft's website the .Net framework's System.IO will not work with Windows 98. Is this true? I designed my app for use with Windows 2000 and Windows XP. However, a user...
5
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...
0
by: mabra | last post by:
Hi All ! I am fighting with watching a large amount of files for their content and look for some keywords, which indicate dangerous error situations to me. This costs me currently hours each...
5
by: =?Utf-8?B?Sm9obiBT?= | last post by:
I am trying to find out if there is a way to tell if there is already a filesystemwatcher (created by a webservice) monitoring a folder. I have a webservice that creates a filesystemwatcher,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
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...

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.