473,748 Members | 11,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple events triggered by fileSystemWatch er

Hi there,

I was trying to write a simple NT services using .NET 2.0 and
fileSystemWatch er control. The goal is to poll documents from a watch
directory and ftp them to a remote web site.

I created a Windows Services project using VS2005. Drag a fileSystemWatch er
control to the designer and added the following code. Here is what I found
out when I create a new file under the watch directory:
1) Using notepad - OnCreate event triggered 2 times. OnChange event
triggered 3 times.
2) Pipe a new file, for example, dir > c:\[watchdir]\temp.txt - OnCreate
event triggered 1 time. OnChange event triggered 3 times.

If I modify a file under the watch directory, Onchange event triggered 2
times.

I think the OnCreate event should work OK. It should be able to pick up new
file and just fire OnCreate event once. Inside the OnCreate event, I can FTP
the file to the site I want.

However, what if user wants to redrop an updated file with the same filename
to the watch directory? How can I reduce the OnChange event to only fire
once? I looked at the MSDN and it states that multiple events could be
triggered but it doesn't provide a solution.

Could you help? If I can't resolve this, I might need to use another
solution besides fileSystemWatch er control. I don't want to post the same
document 2 to 3 times for no reason.

Thanks.

Abel Chan

// Extracted code
private void InitializeCompo nent()
{
this.fileSystem WatcherFTP = new System.IO.FileS ystemWatcher();

((System.Compon entModel.ISuppo rtInitialize)(t his.fileSystemW atcherFTP)).Beg inInit();
//
// fileSystemWatch erFTP
//
this.fileSystem WatcherFTP.Enab leRaisingEvents = true;
this.fileSystem WatcherFTP.Noti fyFilter =
((System.IO.Not ifyFilters)((Sy stem.IO.NotifyF ilters.FileName |
System.IO.Notif yFilters.LastWr ite)));
this.fileSystem WatcherFTP.Chan ged += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcherFTP_C hanged);
this.fileSystem WatcherFTP.Crea ted += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcherFTP_C reate);

//this.fileSystem WatcherFTP.Wait ForChanged(Syst em.IO.WatcherCh angeTypes.Creat ed | System.IO.Watch erChangeTypes.C hanged);

//
// ServiceFTP
//
this.ServiceNam e = "ServiceFTP ";

((System.Compon entModel.ISuppo rtInitialize)(t his.fileSystemW atcherFTP)).End Init();

}
May 11 '06 #1
1 10441
Hello,

This is a known issue. By design, the framework is passing through the
native OS events, which may be any number of things, depending on the way
the file was changed/Created. A work around is to record last file name
"catched" by the control and exact "catch" time. If a second event has same
filename and similiar time, that event will be ignored.

Regards,

Luke Zhang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

May 12 '06 #2

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

Similar topics

3
9478
by: Michael Stanbrook | last post by:
I'm using the FileSystemWatcher to looks for new files arriving in a directory. Files are coming in via FTP and tend to be larger is size (> 1MB at least). I would like to fire an event once the file is completely written. I understand there is nothing "exactly" like that due to how the OS filesystem works, so I am looking for a workaround. I am currently attempting to open the "new" file in
2
10930
by: news.hp.com | last post by:
I have situation where I need to copy multiple records (only certain fields) from a Rules table to an Events table based on a selection identified in a combo box. When the selection is made in a parent table, multiple records in a child table are affected. However, I'm a bit weak on programming experience. INSERT INTO is not suitable. Any ideas? When the combo box update property is triggered, the code needs to accomplish: IF...
4
10871
by: Ken Madden | last post by:
I want to create multiple fileSystemWatchers in a Windows Service to constantly watch multiple folders for file creations and then execute certain code based on these actions. The problem is that these directories are not part of the same directory so I cannot use the subfolder flag. The number of folders also has to be dynamic so I cannot simply create a certain number of FileSystemWatchers with different paths. I am going to pull a...
5
9753
by: Jon Maz | last post by:
Hi there, I am experimenting with the FileSystemWatcher object. I have set the NotifyFilter as follows: myFileSystemWatcher.NotifyFilter = NotifyFilters.Security | NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.Attributes |
5
8331
by: zfeld | last post by:
I am serializing an object to XML and writing it to disk. whenever a change to my object occurs I call the save function to re-write to disk (see code below). I am monitoring the directory where this write is being done using a FileSystemWatcher. My problem is that my Watcher.Changed callback is always invoked twice.This is causing me to process the change twice (causing a performance hit). I am filtering to only be notified for...
3
14306
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 the first thread. I can't really see the sence in this. Aren't the events of the...
10
1710
by: Kai Thorsrud | last post by:
Hi i'm an event Noob and i'm calling a class from my main module console app like this. I'm sorry if this is a lot of code to read but i can't see the error according to my book. Thanks a LOT. if there are other noobs here like me feel free to use my code if it's of any use :) I've set a breakpoint at doWorkOnChangedFile but notinh happens... i'm flooding my log like hell.
12
2209
by: cj | last post by:
I would like to have menu items a main menu bar that represent the days of the week. When you click on them they alternate from checked to unchecked. Right now I have 7 subs that look like this one: Private Sub SunMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SunMenuItem.Click If SunMenuItem.Checked Then SunMenuItem.Checked = False Else SunMenuItem.Checked = True
1
2678
by: D2 | last post by:
Hi, I have this problem when working with FileSystemWatcher class. I m using one of these objects to watch over a folder. Whenever i big file from another folder to the folder being watched, I get created event and multiple changed events. After the file is copied (fully) i want to read the file and perform some operations on it. Now the issue is, there is no way to find that the file has been copied entirely.
0
8989
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8241
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3309
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

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.