[Mono-bugs] [Bug 79893][Maj] New - FSW not working properly

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Nov 10 11:39:20 EST 2006


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 mickaelpic at yahoo.fr.

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

--- shadow/79893	2006-11-10 11:39:20.000000000 -0500
+++ shadow/79893.tmp.9985	2006-11-10 11:39:20.000000000 -0500
@@ -0,0 +1,340 @@
+Bug#: 79893
+Product: Mono: Runtime
+Version: unspecified
+OS: other
+OS Details: RedHat EL 4
+Status: NEW   
+Resolution: 
+Severity: 008 One day
+Priority: Major
+Component: io-layer
+AssignedTo: dick at ximian.com                            
+ReportedBy: mickaelpic at yahoo.fr               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: FSW not working properly
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+The FileSystemWatcher does not get all the events.
+Somtime it even ignore all event.
+It seems to be related to the number of files/directories allready in the 
+watched folder.
+The less files/directories there are in a watch folder, the better the FSW 
+performs.
+The strangest thing is that the problem seems to affect more than one 
+watch. If one watch has a lot of files/directories, there is a high 
+probability to not get events from it, and the next watch with no 
+files/directory will send no events at all.
+
+
+Steps to reproduce the problem:
+1. Compile and start the code I join to this report.
+2. Copy directories and files (50000 files in 340 directories) to a watch 
+folder, and check the output of the application
+3. Delete the folders and check the output
+
+Actual Results:
+(first number is number of events received, second number is number of 
+files/directories that raised an event)
+
+Copy the directories/files
+/home/user1/watch1/ Create: 25041 25041
+/home/user1/watch1/ Change: 329 215
+/home/user1/watch1/ Delete: 0 0
+/home/user1/watch1/ Rename: 0 0
+/home/user1/watch1/ Error: 0 0
+Delete the directories files
+/home/user1/watch1/ Create: 25041 25041
+/home/user1/watch1/ Change: 329 215
+/home/user1/watch1/ Delete: 0 0
+/home/user1/watch1/ Rename: 0 0
+/home/user1/watch1/ Error: 0 0
+
+Expected Results:
+Copy the directories/files
+/home/user1/watch1/ Create: 50340 50340
+/home/user1/watch1/ Change: 50340 50340
+/home/user1/watch1/ Delete: 0 0
+/home/user1/watch1/ Rename: 0 0
+/home/user1/watch1/ Error: 0 0
+Delete the directories files
+/home/user1/watch1/ Create: 50340 50340
+/home/user1/watch1/ Change: 50340 50340
+/home/user1/watch1/ Delete: 50340 50340
+/home/user1/watch1/ Rename: 0 0
+/home/user1/watch1/ Error: 0 0
+
+How often does this happen? 
+Every time, but the number of events received is different everytime.
+But never the good amount.
+
+Additional Information:
+Following is the code for the test application
+
+-----
+
+using System;
+using System.IO;
+using System.Threading;
+using System.Collections;
+
+namespace FSWtester
+{
+	class MainClass
+	{
+		public static void Main(string[] args)
+		{
+			try
+			{
+				if(args.Length == 0)
+				{
+					Console.WriteLine("FSWTester 
+directories");
+					return;
+				}
+				
+				Thread[] threadArray = null;
+				Processing processing = null;
+				string[] directories = null;
+				
+				directories = new string[args.Length];
+				for(int i = 0; i < directories.Length; i 
+++)
+				{
+					directories[i] = args[i];
+				}
+
+				threadArray = new Thread
+[directories.Length];
+				
+				int minWorker, minIOC;
+				ThreadPool.GetMinThreads(out minWorker, 
+out minIOC);
+				Console.WriteLine(minWorker + " " + 
+minIOC);
+				
+				ThreadPool.GetMaxThreads(out minWorker, 
+out minIOC);
+				Console.WriteLine(minWorker + " " + 
+minIOC);
+
+				ThreadPool.SetMinThreads(10, 10);
+
+				ThreadPool.GetMinThreads(out minWorker, 
+out minIOC);
+				Console.WriteLine(minWorker + " " + 
+minIOC);
+				
+				for(int i = 0; i < threadArray.Length; i 
+++)
+				{
+					processing = new Processing
+(directories[i]);
+					threadArray[i] = new Thread
+(processing.Watching);
+                	threadArray[i].Name = "Processing " + i.ToString
+("D2");
+                }
+				for (int i = 0; i < threadArray.Length; 
+i++)
+				{
+					threadArray[i].Start();
+				}
+				
+				while(true)
+				{
+					Thread.Sleep(new TimeSpan(0,0,5));
+				}
+			}
+			catch(Exception ex)
+			{
+				Console.WriteLine("Exception! System 
+reports: " + ex.ToString());
+			}
+		}
+		
+		public class Processing
+		{
+			private FileSystemWatcher fSW = new 
+FileSystemWatcher();
+			private int deleteCount = 0;
+			private Hashtable hashtableDelete = new Hashtable
+();
+			private int createCount = 0;
+			private Hashtable hashtableCreate = new Hashtable
+();
+			private int changeCount = 0;
+			private Hashtable hashtableChange = new Hashtable
+();
+			private int renameCount = 0;
+			private Hashtable hashtableRename = new Hashtable
+();
+			private int errorCount = 0;
+			private string directory = string.Empty;
+
+			public Processing(string directory)
+			{
+				this.directory = directory;
+			}			
+		
+			public void Watching()
+			{
+				try
+				{
+					//fSW.BeginInit();
+
+					Console.WriteLine("Monitoring 
+directory: " + directory);
+
+					try
+					{
+						fSW.Path = directory;
+					}
+					catch (System.Exception ex)
+					{
+						// directory to watch is 
+bad or offline
+						Console.WriteLine("Could 
+not start File System Watch on directory " + directory  + ". Directory 
+does not exist or is corrupted. System reports: " + ex.ToString());
+						return;
+					}
+					
+					fSW.IncludeSubdirectories = true;
+				
+					fSW.NotifyFilter = 
+NotifyFilters.CreationTime | NotifyFilters.LastWrite | 
+NotifyFilters.FileName | NotifyFilters.DirectoryName;			
+			
+
+					fSW.InternalBufferSize = 
+125829120; // 120MB
+
+					fSW.Changed += new 
+FileSystemEventHandler(OnChanged);
+					fSW.Created += new 
+FileSystemEventHandler(OnCreated);
+					fSW.Deleted += new 
+FileSystemEventHandler(OnDeleted);
+					fSW.Renamed += new 
+RenamedEventHandler(OnRename);
+
+					fSW.Error	+= new 
+ErrorEventHandler(OnError);
+					
+					fSW.EnableRaisingEvents = true;
+
+					Thread.CurrentThread.Priority = 
+System.Threading.ThreadPriority.AboveNormal;
+					//fSW.EndInit();
+					
+					while(true)
+					{
+						Thread.Sleep(new TimeSpan
+(0,0,5));
+						Console.WriteLine
+(directory + " Create: " + createCount + " " + hashtableCreate.Count);
+						Console.WriteLine
+(directory + " Change: " + changeCount + " " + hashtableChange.Count);
+						Console.WriteLine
+(directory + " Delete: " + deleteCount + " " + hashtableDelete.Count);
+						Console.WriteLine
+(directory + " Rename: " + renameCount + " " + hashtableRename.Count);
+						Console.WriteLine
+(directory + " Error : " + errorCount);
+						Console.WriteLine("-------
+");
+					}
+				}
+				catch(Exception ex)
+				{
+					Console.WriteLine("Exception! 
+System reports: " + ex.ToString());
+				}
+			}
+			
+			public void OnCreated(object source, 
+FileSystemEventArgs e)
+			{
+				createCount ++;
+				//Console.WriteLine("Create event for 
+file " + e.FullPath);
+				if(hashtableCreate.ContainsKey(e.FullPath) 
+== false)
+				{
+					hashtableCreate.Add(e.FullPath, 1);
+				}
+				else
+				{
+					hashtableCreate[e.FullPath] = (int)
+hashtableCreate[e.FullPath] + 1; 
+				}
+			}
+
+			public void OnChanged(object source, 
+FileSystemEventArgs e)
+			{		
+				changeCount ++;	
+				//Console.WriteLine("Change event for 
+file " + e.FullPath);
+				if(hashtableChange.ContainsKey(e.FullPath) 
+== false)
+				{
+					hashtableChange.Add(e.FullPath, 1);
+				}
+				else
+				{
+					hashtableChange[e.FullPath] = (int)
+hashtableChange[e.FullPath] + 1; 
+				}
+			}
+
+			public void OnDeleted(object source, 
+FileSystemEventArgs e)
+			{
+				deleteCount ++;
+				//Console.WriteLine("Delete event for 
+file " + e.FullPath);
+				if(hashtableDelete.ContainsKey(e.FullPath) 
+== false)
+				{
+					hashtableDelete.Add(e.FullPath, 1);
+				}
+				else
+				{
+					hashtableDelete[e.FullPath] = (int)
+hashtableDelete[e.FullPath] + 1; 
+				}
+			}
+			
+			public void OnRename(object source, 
+RenamedEventArgs e)
+			{
+				renameCount ++;
+				//Console.WriteLine("Rename event for 
+file " + e.FullPath);
+				if(hashtableRename.ContainsKey(e.FullPath) 
+== false)
+				{
+					hashtableRename.Add(e.FullPath, 1);
+				}
+				else
+				{
+					hashtableRename[e.FullPath] = (int)
+hashtableRename[e.FullPath] + 1; 
+				}
+			}
+
+			public void OnError(object source, ErrorEventArgs  
+e)
+			{
+				errorCount ++;
+				//Console.WriteLine("Error event");
+			}
+		}
+	}
+}


More information about the mono-bugs mailing list