473,569 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.IO.FileS ystemWatcher

System.IO.FileS ystemWatcher

When a user copies and pastes a file from one directory to a directory that is monitored
by the FileSystemWatch er, the FileSystemWatch er 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 3473
Hi this is a bug from Microsoft in this Obj

''' <remarks>Implem enting a trick to stop double call from the onChange
FileSystemWatch er event bug</remarks>
Protected Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEvent Args)
Try

If lastChange <>
TimeSpan.FromTi cks(Now.Ticks). TotalMillisecon ds Then
'DO YOUR STUFF HERE
End If

lastChange =
TimeSpan.FromTi cks(Now.Ticks). TotalMillisecon ds

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

Finally
End Try

End Sub

Hope this help

Nicolas

"John Talli" wrote:
System.IO.FileS ystemWatcher

When a user copies and pastes a file from one directory to a directory that is monitored
by the FileSystemWatch er, the FileSystemWatch er 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*****@discus sions.microsoft .comwrote in message
news:87******** *************** ***********@mic rosoft.com...
Hi this is a bug from Microsoft in this Obj

''' <remarks>Implem enting a trick to stop double call from the onChange
FileSystemWatch er event bug</remarks>
Protected Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEvent Args)
Try

If lastChange <>
TimeSpan.FromTi cks(Now.Ticks). TotalMillisecon ds Then
'DO YOUR STUFF HERE
End If

lastChange =
TimeSpan.FromTi cks(Now.Ticks). TotalMillisecon ds

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

Finally
End Try

End Sub

Hope this help

Nicolas

"John Talli" wrote:
>System.IO.File SystemWatcher

When a user copies and pastes a file from one directory to a directory that is
monitored
by the FileSystemWatch er, the FileSystemWatch er 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
4101
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 when its done. Does anyone know the right combination of flags to use to catch when the file has been written and closed? (here is my current code)....
2
3301
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 a couple of different directories and based upon the directory where the new file is created kick-off a process Example: File A in Directory B...
2
2482
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 notify_NewImage(string imageName); } Then there is the delegate:
3
14242
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 a working thread for processing the file, created a new FileSystemWatcher (as he said for real time processing), and then called the join method for...
20
4434
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 logic layer(so far so good and easy).I initialize my class which is using a FileSystemWatcher in my Global.asax and everything works fine.I have...
11
1580
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 is trying in on a Windows 98 box and having some issues. I have labels which are filled by reading files in the file system and he is telling me that...
5
5127
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 7000 files in the directory to be monitored only 123 are sent to the service. What might be going wrong?
0
1598
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 day. I know, how to use the FileSystemWatcher class. But in my case, I would like to open about 500 files and watch each of them for progress/enlarge...
5
5563
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, monitors a folder and then returns the contents of the new/changed files. However, if the client app loses connection to the webservice without...
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.