473,839 Members | 1,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A problem about FileSystemWathc her(BUG???)

Sir:
I have used FileSystemWathc her(.NET class) to monitor file change
envent.The code as list:

............... .......

int i=0; //Counter for Changed event after FileCreated event
private void IntializeFileSy stemWatcher()
{
//Create File System Watcher in mypath for new files
fsWatcher=new System.IO.FileS ystemWatcher(my path,"*.*");

// Add event handlers for new files and change of existing files.
fsWatcher.Chang ed += new FileSystemEvent Handler(OnFileC hanged);
fsWatcher.Creat ed += new FileSystemEvent Handler(OnFileC reated);

// Begin watching.
fsWatcher.Enabl eRaisingEvents = true;

}

private void OnFileChanged(o bject source, FileSystemEvent Args e)
{
i++;
}

/// <summary>
/// Event Handler for File Created
///
/// </summary>
private void OnFileCreated(o bject source, FileSystemEvent Args e)
{
i=0;
Thread thread=new Thread(new ThreadStart(thi s.StartListen)) ;
thread.Start();
}

//Wait for Changed event fired,But only get once.
void StartListen()
{
WaitForChangedR esult
r=fsWatcher.Wai tForChanged(Wat cherChangeTypes .Changed);
bool b=r.TimedOut;
}
............... .......

When I break at "bool b=r.TiedOut" this line,I got only one Changed
event.But when I check i value,it is more then 1.
Why????
inexplicability !!!!
Is there something wrong? Can you help me to explain this situation?
Thank You!!!

Apr 5 '06 #1
2 1609
If you have a lot of changes in a small time, you might get just one
notification.

From
http://msdn2.microsoft.com/en-us/lib...ze(VS.80).aspx

"The Windows operating system notifies your component of file changes in a
buffer created by the FileSystemWatch er. If there are many changes in a
short time, the buffer can overflow. This causes the component to lose track
of changes in the directory, and it will only provide blanket notification."

Laura

"gates.liu" <ga*******@disc ussions.microso ft.com> ha scritto nel messaggio
news:8D******** *************** ***********@mic rosoft.com...
Sir:
I have used FileSystemWathc her(.NET class) to monitor file change
envent.The code as list:

............... .......

int i=0; //Counter for Changed event after FileCreated event
private void IntializeFileSy stemWatcher()
{
//Create File System Watcher in mypath for new files
fsWatcher=new System.IO.FileS ystemWatcher(my path,"*.*");

// Add event handlers for new files and change of existing files.
fsWatcher.Chang ed += new FileSystemEvent Handler(OnFileC hanged);
fsWatcher.Creat ed += new FileSystemEvent Handler(OnFileC reated);

// Begin watching.
fsWatcher.Enabl eRaisingEvents = true;

}

private void OnFileChanged(o bject source, FileSystemEvent Args e)
{
i++;
}

/// <summary>
/// Event Handler for File Created
///
/// </summary>
private void OnFileCreated(o bject source, FileSystemEvent Args e)
{
i=0;
Thread thread=new Thread(new ThreadStart(thi s.StartListen)) ;
thread.Start();
}

//Wait for Changed event fired,But only get once.
void StartListen()
{
WaitForChangedR esult
r=fsWatcher.Wai tForChanged(Wat cherChangeTypes .Changed);
bool b=r.TimedOut;
}
............... .......

When I break at "bool b=r.TiedOut" this line,I got only one Changed
event.But when I check i value,it is more then 1.
Why????
inexplicability !!!!
Is there something wrong? Can you help me to explain this situation?
Thank You!!!


Apr 5 '06 #2
You are right about event buffer.

My code can capture more then one changed event notify. But use
WaitForChanged( ) API,I can only capture 1 changed event,where are others? I
want to know underground processing about event notify, maybe I can get
explain with more reason.

“Laura T.”编写:
If you have a lot of changes in a small time, you might get just one
notification.

From
http://msdn2.microsoft.com/en-us/lib...ze(VS.80).aspx

"The Windows operating system notifies your component of file changes in a
buffer created by the FileSystemWatch er. If there are many changes in a
short time, the buffer can overflow. This causes the component to lose track
of changes in the directory, and it will only provide blanket notification."

Laura

"gates.liu" <ga*******@disc ussions.microso ft.com> ha scritto nel messaggio
news:8D******** *************** ***********@mic rosoft.com...
Sir:
I have used FileSystemWathc her(.NET class) to monitor file change
envent.The code as list:

............... .......

int i=0; //Counter for Changed event after FileCreated event
private void IntializeFileSy stemWatcher()
{
//Create File System Watcher in mypath for new files
fsWatcher=new System.IO.FileS ystemWatcher(my path,"*.*");

// Add event handlers for new files and change of existing files.
fsWatcher.Chang ed += new FileSystemEvent Handler(OnFileC hanged);
fsWatcher.Creat ed += new FileSystemEvent Handler(OnFileC reated);

// Begin watching.
fsWatcher.Enabl eRaisingEvents = true;

}

private void OnFileChanged(o bject source, FileSystemEvent Args e)
{
i++;
}

/// <summary>
/// Event Handler for File Created
///
/// </summary>
private void OnFileCreated(o bject source, FileSystemEvent Args e)
{
i=0;
Thread thread=new Thread(new ThreadStart(thi s.StartListen)) ;
thread.Start();
}

//Wait for Changed event fired,But only get once.
void StartListen()
{
WaitForChangedR esult
r=fsWatcher.Wai tForChanged(Wat cherChangeTypes .Changed);
bool b=r.TimedOut;
}
............... .......

When I break at "bool b=r.TiedOut" this line,I got only one Changed
event.But when I check i value,it is more then 1.
Why????
inexplicability !!!!
Is there something wrong? Can you help me to explain this situation?
Thank You!!!


Apr 6 '06 #3

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

Similar topics

1
2863
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew story is so funny that eScrew will have to take break from time to time because eScrew needs some rest from laughing. Oh boy, here it comes... eScrew funny laugh laughing screaming crying must stop can not take any more this is killing eScrew...
220
19236
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
54
6596
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a...
8
2467
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew story is so funny that eScrew will have to take break from time to time because eScrew needs some rest from laughing. Oh boy, here it comes... eScrew funny laugh laughing screaming crying must stop can not take any more this is killing eScrew...
77
5700
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a database from SQL Server to Oracle or DB2 or vice versa... and that's it.... And a lot of these enterprises don't need it as they already know what database they are going to use and they don't plan on switching in and out database in the first...
125
14906
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
5
3011
by: eScrewDotCom | last post by:
www.eScrew.com eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew story is so funny that eScrew will have to take break from time to time because eScrew needs some rest from laughing. Oh boy, here it comes... eScrew funny laugh laughing
0
2465
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew story is so funny that eScrew will have to take break from time to time because eScrew needs some rest from laughing. Oh boy, here it comes... eScrew funny laugh laughing screaming crying must stop can not take any more this is killing eScrew...
7
3160
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my question about local variable initialization is still not solved. And some of the replies forked into talking about out parameters. And the thread is becoming way too deep. So I open a new thread here. My question in the previous thead has turned...
0
9855
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9697
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
10908
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10586
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...
0
9426
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 projectplanning, coding, testing, and deploymentwithout 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...
0
5682
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...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4484
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
3
3134
bsmnconsultancy
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...

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.