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();
} 1 10445
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.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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...
|
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...
|
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 |
|
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...
| |
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...
|
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.
|
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
|
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.
|
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,...
|
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...
| |
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |