FileSystemWatcher

K

Ken

I set up a FileSystemWatcher to watch one specific file, code sample below.
I have set the NotifyFilter to NotifyFilters.LastWrite. When the file is
saved Class1.WeChanged is fired 2 times. Does anyone know why this would
be? I understand that a rename or a move causes multiple events to be fired
but don't know why LastWrite would get fired more than once.

FileSystemWatcher fs = new FileSystemWatcher ( );
fs.Path = ".\\";
fs.Filter = "Test.dat";
fs.NotifyFilter = NotifyFilters.LastWrite;
fs.Changed += new FileSystemEventHandler ( Class1.WeChanged );
fs.EnableRaisingEvents = true;

Thank You

Ken
 
T

Tian Min Huang

Hello Ken,

Thanks for your post. As I understand, the problem you are facing is why
NotifyFilters.LastWrite is triggered twice when you save a file. Please
correct me if there is any misunderstanding. I now share the following
information with you:

Generally speaking, there are two steps when we save a file:
1. Save the content of the file, it will send the IRP_MJ_WRITE to the
underlying driver.
2. Update the file information by sending the IRP_MJ_SET_INFORMATION.

I believe that the reason why LastWrite will be triggered twice.

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top