473,395 Members | 1,936 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.

FileSystemWatcher Changed Event Double Activation

I'm using VB.net 2003 and a FileSystemWatcher. The Changed event gets
called twice for every change in the folder I'm watching. To build the
functionality, I'm manually changing a text file. As soon as I save the
changed file, the event is called, which is great. But then the event
is called again almost immediately. That causes some serious issues for
my program.

Has anyone seen this before? Is there a way to stop it?

Thanks

Tom
Feb 7 '08 #1
4 7194
I had a problem with this when my notifyfilter contained 2 filters that
could both conveivably be hit with a single change ie:

fsw.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Size

If I write to the file, and the filesize also changes, then this gets raised
once for the lastwrite, and once for the size change. (In the case of
notepad, it seems the Size change happens regardless as I think notepad
re-writes the complete file.

In my case, I just used the lastwrite notification filter, and that solved
my problem, because all I cared about was whether the file had been written
to.

Lance

"tomb" <to**@technetcenter.comwrote in message
news:2z*******************@bignews7.bellsouth.net. ..
I'm using VB.net 2003 and a FileSystemWatcher. The Changed event gets
called twice for every change in the folder I'm watching. To build the
functionality, I'm manually changing a text file. As soon as I save the
changed file, the event is called, which is great. But then the event is
called again almost immediately. That causes some serious issues for my
program.

Has anyone seen this before? Is there a way to stop it?

Thanks

Tom

Feb 7 '08 #2
This sounded like it should resolve the issue, but it didn't. I set the
filter to lastwrite, and the changed event still gets called twice. Is
this a bug in V2003?

T

Lance Wynn wrote:
I had a problem with this when my notifyfilter contained 2 filters that
could both conveivably be hit with a single change ie:

fsw.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Size

If I write to the file, and the filesize also changes, then this gets raised
once for the lastwrite, and once for the size change. (In the case of
notepad, it seems the Size change happens regardless as I think notepad
re-writes the complete file.

In my case, I just used the lastwrite notification filter, and that solved
my problem, because all I cared about was whether the file had been written
to.

Lance

"tomb" <to**@technetcenter.comwrote in message
news:2z*******************@bignews7.bellsouth.net. ..
>I'm using VB.net 2003 and a FileSystemWatcher. The Changed event gets
called twice for every change in the folder I'm watching. To build the
functionality, I'm manually changing a text file. As soon as I save the
changed file, the event is called, which is great. But then the event is
called again almost immediately. That causes some serious issues for my
program.

Has anyone seen this before? Is there a way to stop it?

Thanks

Tom

Feb 7 '08 #3
It must be the way you are testing the file. If you are using notepad, I
think it resets the file, and rewrites the whole thing.
In my case, I had a lazy reader that read the tail end of a log file when it
changed. As I recall I saw this problem when using notepad to add lines to
the end of the file. I just tested with both filters in place, and used:
echo test >test.txt
from a command line to append text to the end of the file, and it works as
expected even with both filters in place. So I suspect my original post was
incorrect as to the cause. And the actual culprit is the way notepad
modifies the file.
"tomb" <to**@technetcenter.comwrote in message
news:2X*******************@bignews7.bellsouth.net. ..
This sounded like it should resolve the issue, but it didn't. I set the
filter to lastwrite, and the changed event still gets called twice. Is
this a bug in V2003?

T

Lance Wynn wrote:
>I had a problem with this when my notifyfilter contained 2 filters that
could both conveivably be hit with a single change ie:

fsw.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Size

If I write to the file, and the filesize also changes, then this gets
raised once for the lastwrite, and once for the size change. (In the
case of notepad, it seems the Size change happens regardless as I think
notepad re-writes the complete file.

In my case, I just used the lastwrite notification filter, and that
solved my problem, because all I cared about was whether the file had
been written to.

Lance

"tomb" <to**@technetcenter.comwrote in message
news:2z*******************@bignews7.bellsouth.net ...
>>I'm using VB.net 2003 and a FileSystemWatcher. The Changed event gets
called twice for every change in the folder I'm watching. To build the
functionality, I'm manually changing a text file. As soon as I save the
changed file, the event is called, which is great. But then the event
is called again almost immediately. That causes some serious issues for
my program.

Has anyone seen this before? Is there a way to stop it?

Thanks

Tom
Feb 7 '08 #4
Well, I tested it using the program that would actually be affecting the
files. It is a vb.net application using a dataset. The dataset just
calls WriteXml() to save the data it is holding.

My FileSystemWatcher captures the file update, but it is still being
activated twice. This is not good.

Can you think of some way around this? I was thinking of using a flag,
but I can't figure out how to make that work. The file could
conceivably be updated every 60 seconds. I could deactivate the watcher
for 20 seconds immediately upon activation, but that seems so cloogy.

Thanks,

T
Lance Wynn wrote:
It must be the way you are testing the file. If you are using notepad, I
think it resets the file, and rewrites the whole thing.
In my case, I had a lazy reader that read the tail end of a log file when it
changed. As I recall I saw this problem when using notepad to add lines to
the end of the file. I just tested with both filters in place, and used:
echo test >test.txt
from a command line to append text to the end of the file, and it works as
expected even with both filters in place. So I suspect my original post was
incorrect as to the cause. And the actual culprit is the way notepad
modifies the file.
"tomb" <to**@technetcenter.comwrote in message
news:2X*******************@bignews7.bellsouth.net. ..
>This sounded like it should resolve the issue, but it didn't. I set the
filter to lastwrite, and the changed event still gets called twice. Is
this a bug in V2003?

T

Lance Wynn wrote:
>>I had a problem with this when my notifyfilter contained 2 filters that
could both conveivably be hit with a single change ie:

fsw.NotifyFilter = NotifyFilters.LastWrite Or NotifyFilters.Size

If I write to the file, and the filesize also changes, then this gets
raised once for the lastwrite, and once for the size change. (In the
case of notepad, it seems the Size change happens regardless as I think
notepad re-writes the complete file.

In my case, I just used the lastwrite notification filter, and that
solved my problem, because all I cared about was whether the file had
been written to.

Lance

"tomb" <to**@technetcenter.comwrote in message
news:2z*******************@bignews7.bellsouth.ne t...
I'm using VB.net 2003 and a FileSystemWatcher. The Changed event gets
called twice for every change in the folder I'm watching. To build the
functionality, I'm manually changing a text file. As soon as I save the
changed file, the event is called, which is great. But then the event
is called again almost immediately. That causes some serious issues for
my program.

Has anyone seen this before? Is there a way to stop it?

Thanks

Tom
Feb 7 '08 #5

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

Similar topics

4
by: Josh Usovsky | last post by:
I'm setting up a watched folder using FileSystemWatcher. When I drop a small file into the watched folder, I can respond to a .Created event and process the file with other code. However, if I try...
1
by: Troy Murphy | last post by:
How do I prevent the FileSystemWatcher event to keep firing while the file is being created? When copying a file to the watched folder, the event fires a dozen or more times! Also, the...
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...
0
by: Peter Kirk | last post by:
Hi I am trying to use FileSystemWatcher to watch for changes in a directory. The problem I am exepriencing is a double firing of an OnChanged event when a file is opened, edited, and saved. Why...
1
by: Peter Kirk | last post by:
Hi I am trying to use FileSystemWatcher to watch for changes in a directory. The problem I am exepriencing is a double firing of an OnChanged event when a file is opened, edited, and saved. Why...
1
by: Abel Chan | last post by:
Hi there, I was trying to write a simple NT services using .NET 2.0 and fileSystemWatcher control. The goal is to poll documents from a watch directory and ftp them to a remote web site. I...
1
by: teslar91 | last post by:
I've been learning VB.NET for the past few weeks. One of the problems I've run into is difficulties updating controls in events from certain components, such as the FileSystemWatcher, that raise...
3
by: =?Utf-8?B?RGFuaWVs?= | last post by:
I'm working with the FileSystemWatcher which has a Created event. But this event is raised as soon as the new file begins to be written on disk. What I want is a notification after a file being...
2
by: John Talli | last post by:
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...
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: 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?
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
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:
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.