si ho notato guardando qua http://msdn.microsoft.com/it-it/libr...yfilters.aspx.
ho solo ancora due domandine:
c'è un modo secondo te per specificare la notifica nell'output?codice:using System; using System.Text; using System.IO; namespace DirectoryMonitor { class DirMonitor { public DirMonitor(string controlDir) { while (true) { FileSystemWatcher fw = new FileSystemWatcher(); fw.Path = controlDir; fw.IncludeSubdirectories = true; fw.EnableRaisingEvents = true; fw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; //fw.Changed += new FileSystemEventHandler(OnChanged); fw.Created += new FileSystemEventHandler(OnChanged); fw.Deleted += new FileSystemEventHandler(OnChanged); fw.Renamed += new RenamedEventHandler(OnRenamed); } } private void OnChanged(object source, FileSystemEventArgs e) { DateTime dt = new DateTime(); dt = DateTime.UtcNow; Console.WriteLine("Path: " + e.FullPath + " " + e.ChangeType + " at " + dt.ToLocalTime()); } private void OnRenamed(object source, RenamedEventArgs e) { DateTime dt = new DateTime(); dt = DateTime.UtcNow; Console.WriteLine("Old path:" + e.OldFullPath + " Path: " + e.FullPath + " " + e.ChangeType + " at " + dt.ToLocalTime()); } } }
cioè se è stato LastAccess, LastWrite,....
poi mi pare di aver capito che la riga commentata:
è inutile se metto Deleted, Created e Renamed, in quanto Changed è più generico giusto?codice://fw.Changed += new FileSystemEventHandler(OnChanged); fw.Created += new FileSystemEventHandler(OnChanged); fw.Deleted += new FileSystemEventHandler(OnChanged); fw.Renamed += new RenamedEventHandler(OnRenamed);
cmq ho notato che le operazioni dentro la cartella controllata sono più lente.

Rispondi quotando