FileSystemWatcher failure

  • Thread starter Thread starter MPS35
  • Start date Start date
M

MPS35

I am using the FileSystemWatcher in our product to watch for file creations,
changes, and deletions and updating the UI of our product based on those
notifications. I have a customer that is not seeing his UI update and I
have traced it to not getting the notifications from the FileSystemWatcher.
I even had him run a test using sample code pulled from MSDN to verify that
we should be getting notifications, and that nothing with our product was
inhibiting this. He has tried this on two computers. On the first computer
(XP Pro SP1), we will call this computer A, he is having problem described
above, if the files are located on a network server (SBS 2000). On computer
A, the customer seems to have no problems if the files are local. I had him
install and test on another computer. We will call this second computer,
computer B. On computer B (XP Pro SP2), using the same network server,
share, and files that wouldn't work with computer A all seems to work
without incident. In-house, we were able to somewhat reproduce this, but
only with Windows 2000 installed on Virtual PC. In that Virtual PC we got
some notifications but very few. If we ran the same tests on the same
computer (XP Pro SP2) that the Virtual PC was being run on, but not using
Virtual PC, we received all the notifications that we should have. Does
anyone have any idea what might be causing this?

MPS35
 
Hi,

Currently I am researching the issue and we will reply here with more
information as soon as possible.
If you have any more concerns on it, please feel free to post here.

Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

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

Based on my test with Window XP+SP1 to access to a folder on Windows 2000
Server + SP4, it can not get the notification.
Here is my test code.
using System;
using System.IO;
using System.Diagnostics;
namespace FWT
{
public class Watcher
{

public static void Main()
{

string[] args = System.Environment.GetCommandLineArgs();

// If a directory is not specified, exit program.
if(args.Length != 2)
{
// Display the proper way to call the program.
Console.WriteLine("Usage: Watcher.exe (directory)");
return;
}

// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = args[1];
/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";

// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);

// Begin watching.
watcher.EnableRaisingEvents = true;

// Wait for the user to quit the program.
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}

// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}

private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}
}
}

Also I suggest you try to apply the recently Service Pack before test.
From the Document below, Windows 2000 may lost packet when it has not
install SP2 or high and the VM may have poor performance in contrast with
physically machine.

Windows NT 4.0: The limit in this situation is 4 KB.

Windows 2000: Clients that attempt multiple simultaneous long-term
requests against a server, for example change notifications, should be
running Service Pack 2 or higher. See Knowledge Base article Q271148 for
more details.
Windows Me: There is similar functionality available with the
FindFirstChangeNotification function.

ReadDirectoryChangesW
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/r
eaddirectorychangesw.asp

The FileSystemWatcher will use the API above.

Best regards,

Peter Huang
Microsoft Online Partner Support

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

I'm not sure I understand your reply. Are you saying that you could not get
this to fail? You mention the KB article Q271148. This describes how it
could fail in 2000. Do these same parameters described in that article
exist in XP?

Thanks,
Mike

"Peter Huang" said:
Hi

Based on my test with Window XP+SP1 to access to a folder on Windows 2000
Server + SP4, it can not get the notification.
Here is my test code.
using System;
using System.IO;
using System.Diagnostics;
namespace FWT
{
public class Watcher
{

public static void Main()
{

string[] args = System.Environment.GetCommandLineArgs();

// If a directory is not specified, exit program.
if(args.Length != 2)
{
// Display the proper way to call the program.
Console.WriteLine("Usage: Watcher.exe (directory)");
return;
}

// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = args[1];
/* Watch for changes in LastAccess and LastWrite times, and
the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";

// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);

// Begin watching.
watcher.EnableRaisingEvents = true;

// Wait for the user to quit the program.
Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}

// Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}

private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}
}
}

Also I suggest you try to apply the recently Service Pack before test.
From the Document below, Windows 2000 may lost packet when it has not
install SP2 or high and the VM may have poor performance in contrast with
physically machine.

Windows NT 4.0: The limit in this situation is 4 KB.

Windows 2000: Clients that attempt multiple simultaneous long-term
requests against a server, for example change notifications, should be
running Service Pack 2 or higher. See Knowledge Base article Q271148 for
more details.
Windows Me: There is similar functionality available with the
FindFirstChangeNotification function.

ReadDirectoryChangesW
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/r
eaddirectorychangesw.asp

The FileSystemWatcher will use the API above.

Best regards,

Peter Huang
Microsoft Online Partner Support

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

Per the KB the problem existed in Windows 2000 before service pack 2, I did
not find a similar problem with XP.
Also based on my test, the problem will not persist on a windows XP +SP1.

So I suggest you may try my code on the problem XP+SP1 to see if that is
any difference.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top