FSWatcher icon indicating copy to clipboard operation
FSWatcher copied to clipboard

slow watcher.StopWatching()

Open cchicote opened this issue 7 years ago • 3 comments

Hi, i'm working with your awesome FSWatcher, it's really efficient and reactive but when i call the watcher.StopWatching() method on instances watching directories with a lot of files (>10.000), it takes a lot of time to stop. I'm also working with TPL so i tried to put the method watcher.StopWatching() in a parallel task but it still calls the methods i've linked to the watcher. Do you know a faster way than the regular method to stop an instance of FSWatcher ? Thanks a lot, cchicote

cchicote avatar Mar 13 '18 16:03 cchicote

That is a bit odd. In first glance it should be fast but there may be a way it uses _abortCheck() in getSnapshot routine that has it passing through the entire snapshot anyway.

acken avatar Mar 13 '18 19:03 acken

Yes i see that you use Directory.GetFiles() which is a method that can be really slow with a large amount of files on a distant drive. Is the getSnapshot routine called frequently ? Maybe i ask the watcher to stop while it's calling Directory.GetFiles() and that would explain the slowness of his abort

cchicote avatar Mar 14 '18 11:03 cchicote

Hey i got this piece of code: Console.WriteLine("Stop watcher {0} {1}", cell.Name, DateTime.Now.ToString()); cell.watcher.StopWatching(); Console.WriteLine("Watcher stopped {0} {1}", cell.Name, DateTime.Now.ToString());

It's watching a directory with 20.070 files within 6.896 directories.

And this comes out: Stop watcher Random_task3 15/03/2018 17:24:03 Watcher stopped Random_task3 15/03/2018 18:00:23

During this time, the methods that i gave to the watcher can still be triggered by a file modification inside the watched directory, which is a bit annoying.

cchicote avatar Mar 15 '18 17:03 cchicote