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

A problem about FileSystemWathcher(BUG???)

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

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

int i=0; //Counter for Changed event after FileCreated event
private void IntializeFileSystemWatcher()
{
//Create File System Watcher in mypath for new files
fsWatcher=new System.IO.FileSystemWatcher(mypath,"*.*");

// Add event handlers for new files and change of existing files.
fsWatcher.Changed += new FileSystemEventHandler(OnFileChanged);
fsWatcher.Created += new FileSystemEventHandler(OnFileCreated);

// Begin watching.
fsWatcher.EnableRaisingEvents = true;

}

private void OnFileChanged(object source, FileSystemEventArgs e)
{
i++;
}

/// <summary>
/// Event Handler for File Created
///
/// </summary>
private void OnFileCreated(object source, FileSystemEventArgs e)
{
i=0;
Thread thread=new Thread(new ThreadStart(this.StartListen));
thread.Start();
}

//Wait for Changed event fired,But only get once.
void StartListen()
{
WaitForChangedResult
r=fsWatcher.WaitForChanged(WatcherChangeTypes.Chan ged);
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 1588
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 FileSystemWatcher. 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*******@discussions.microsoft.com> ha scritto nel messaggio
news:8D**********************************@microsof t.com...
Sir:
I have used FileSystemWathcher(.NET class) to monitor file change
envent.The code as list:

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

int i=0; //Counter for Changed event after FileCreated event
private void IntializeFileSystemWatcher()
{
//Create File System Watcher in mypath for new files
fsWatcher=new System.IO.FileSystemWatcher(mypath,"*.*");

// Add event handlers for new files and change of existing files.
fsWatcher.Changed += new FileSystemEventHandler(OnFileChanged);
fsWatcher.Created += new FileSystemEventHandler(OnFileCreated);

// Begin watching.
fsWatcher.EnableRaisingEvents = true;

}

private void OnFileChanged(object source, FileSystemEventArgs e)
{
i++;
}

/// <summary>
/// Event Handler for File Created
///
/// </summary>
private void OnFileCreated(object source, FileSystemEventArgs e)
{
i=0;
Thread thread=new Thread(new ThreadStart(this.StartListen));
thread.Start();
}

//Wait for Changed event fired,But only get once.
void StartListen()
{
WaitForChangedResult
r=fsWatcher.WaitForChanged(WatcherChangeTypes.Chan ged);
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 FileSystemWatcher. 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*******@discussions.microsoft.com> ha scritto nel messaggio
news:8D**********************************@microsof t.com...
Sir:
I have used FileSystemWathcher(.NET class) to monitor file change
envent.The code as list:

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

int i=0; //Counter for Changed event after FileCreated event
private void IntializeFileSystemWatcher()
{
//Create File System Watcher in mypath for new files
fsWatcher=new System.IO.FileSystemWatcher(mypath,"*.*");

// Add event handlers for new files and change of existing files.
fsWatcher.Changed += new FileSystemEventHandler(OnFileChanged);
fsWatcher.Created += new FileSystemEventHandler(OnFileCreated);

// Begin watching.
fsWatcher.EnableRaisingEvents = true;

}

private void OnFileChanged(object source, FileSystemEventArgs e)
{
i++;
}

/// <summary>
/// Event Handler for File Created
///
/// </summary>
private void OnFileCreated(object source, FileSystemEventArgs e)
{
i=0;
Thread thread=new Thread(new ThreadStart(this.StartListen));
thread.Start();
}

//Wait for Changed event fired,But only get once.
void StartListen()
{
WaitForChangedResult
r=fsWatcher.WaitForChanged(WatcherChangeTypes.Chan ged);
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
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...
220
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...
54
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...
8
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...
77
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...
125
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...
5
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...
0
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...
7
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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 projectplanning, 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.