By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,145 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,145 IT Pros & Developers. It's quick & easy.

A problem about FileSystemWathcher(BUG???)

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.