[Mono-bugs] [Bug 72919][Maj] New - Bug in FileSystemWatcher Class

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 23 Feb 2005 10:15:08 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by monotoll@braindrum.de.

http://bugzilla.ximian.com/show_bug.cgi?id=72919

--- shadow/72919	2005-02-23 10:15:08.000000000 -0500
+++ shadow/72919.tmp.10029	2005-02-23 10:15:08.000000000 -0500
@@ -0,0 +1,142 @@
+Bug#: 72919
+Product: Mono: Class Libraries
+Version: 1.1
+OS: SUSE 9.2
+OS Details:  Unix 2.6.8.24
+Status: NEW   
+Resolution: 
+Severity: Unknown
+Priority: Major
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: monotoll@braindrum.de               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Bug in FileSystemWatcher Class
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+If the FileSystemWatcher.IncludeSubdirectories Property is set "true",
+the File watching doesn't work at all.
+
+Steps to reproduce the problem:
+1. see the attached Code and compile
+2. run the Programm without Arguments -> Watch only in the Selected Path -
+> everything fine
+3. run the Programm with Argument "WITH_SUBDIRS" -> Watch also in Subdirs -
+> nothing happens
+
+Actual Results:
+There is no FileSystemWatcher Event fired if "IncludeSubdirectories" is 
+set true
+
+Expected Results:
+If a FileSystemWatcher Event occured, there should be a Message
+in the Console Output
+
+How often does this happen? 
+always
+
+Additional Information:
+
+using System;
+using System.IO;
+
+class  fwatch
+{
+  
+  /*
+         mono fwatch.exe WITH_SUBDIRS   ->  Watch also in Subdirectories
+         mono fwatch.exe                ->  Watch only in selected Path
+  */
+  
+  public static void Main(string[] args)
+  {
+    // Create a new FileSystemWatcher 
+    FileSystemWatcher watcher = new FileSystemWatcher();
+
+    // Setup watcher
+    watcher.NotifyFilter        = NotifyFilters.LastAccess | 
+NotifyFilters.LastWrite | NotifyFilters.FileName   | 
+NotifyFilters.DirectoryName;
+    watcher.Filter              = "*.*";
+    watcher.EnableRaisingEvents = false;
+   
+    // Add event handlers.
+    watcher.Changed += new FileSystemEventHandler(OnChanged);
+    watcher.Created += new FileSystemEventHandler(OnChanged);
+    watcher.Deleted += new FileSystemEventHandler(OnChanged);
+
+    if(args.Length == 1 && args[0].Equals("WITH_SUBDIRS"))
+    {
+     watcher.IncludeSubdirectories = true;
+     Console.WriteLine("Watch also in Subdirectories !");
+    }
+    else
+    {
+     watcher.IncludeSubdirectories = false;
+     Console.WriteLine("Watch only in the selected Path!");
+    }
+        
+    string path= null;
+    
+    while(path==null)
+    {
+       path = EnterPath();  
+    }
+    
+    watcher.Path = path;
+    watcher.EnableRaisingEvents = true;
+   
+    Console.WriteLine("Press \'q\' to quit !");
+    while(Console.Read()!='q');
+  }
+  
+  private static string EnterPath()
+  {
+    Console.WriteLine("Enter Path to watch: ");
+
+    string path = Console.ReadLine();
+
+    if(!Directory.Exists(path))
+    {
+      Console.WriteLine("Path not found - Try again !");
+      return null;
+    }
+
+    Console.WriteLine("Path OK - Start Watching !");
+
+    return path;
+  }
+  
+  public fwatch()
+  {
+   
+  }
+  
+  // Define the event handlers.
+  private static void OnChanged(object source, FileSystemEventArgs e)
+  {
+    try
+    {
+      Console.Write( DateTime.Now.ToString() + " " + "File: " +  
+e.FullPath  + " " + e.ChangeType  + " " );
+
+      if(File.Exists(e.FullPath))
+      {
+        FileInfo fi = new FileInfo(e.FullPath);
+        Console.Write( fi.Length.ToString() + " " + fi.Attributes.ToString
+());
+      }
+    }
+    catch(Exception ex)
+    {
+      Console.Write("Exception occured ! - " + ex.Message);
+    }
+    Console.Write(Environment.NewLine);
+  }
+
+}