Bug 14663 - FileSystemWatcher does not perform as expected
Summary: FileSystemWatcher does not perform as expected
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-09-11 18:39 UTC by Bryan Moulton
Modified: 2014-12-09 01:20 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

FSWatcher (23.39 KB, application/zip)
2013-09-11 18:39 UTC, Bryan Moulton

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 14663 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Bryan Moulton 2013-09-11 18:39:56 UTC
Created attachment 4847 [details]

From case #45521
Using the example provided, the FileSystemWatcher events aren't being handled properly. Only the Changed event is firing, and the ChangeType is always Changed.
Comment 1 Nikolay Ivanets 2013-09-12 06:29:23 UTC
Here is my initial request:

I use Mono on Mac OS X and it seems neither KeventWatcher nor DefaultWatcher implementation of IFileWatcher interface doesn't send Renamed event and thus it is impossible to catch this event when the user renames file or folder. I always get Deleted and Created events successively.
Comment 2 Aaron Bockover [MSFT] 2013-09-26 12:52:44 UTC
Use MonoMac.CoreServices.FSEvents for now. Here's a sample: https://github.com/xamarin/mac-samples/tree/master/FSEvents

Mono at some point in the future should probably use FSEvents internally for FileSystemWatcher, but it does not. The behavior you are looking for is however available in Xamarin.Mac.

Moving this to Mono itself since this is not a bug in Xamarin.Mac.
Comment 3 Nikolay Ivanets 2013-10-02 11:47:07 UTC
Yes, it is what I finally used.
Comment 4 Lorenzo Antonio Brito Morales 2014-05-08 03:43:32 UTC
Hi,  i would like to fix this. Is anyone
Comment 5 Lorenzo Antonio Brito Morales 2014-05-08 04:18:23 UTC
Sorry for my last comment, i would  like to fix, i have seen in code that all events are considerated. is this still a problem?
Comment 6 Nicolas Raoul 2014-12-09 01:20:25 UTC
Bug confirmed with Mono 3.10.0 on OS X 10.9.5.
I have created this watcher which inherits from FileSystemWatcher:

    Path = System.IO.Path.GetFullPath(folder);
    IncludeSubdirectories = true;
    Filter = "*";
    InternalBufferSize = 4 * 1024 * 16;
    NotifyFilter = NotifyFilters.Size |
               NotifyFilters.FileName | NotifyFilters.DirectoryName;
    Error += new ErrorEventHandler(OnError);
    Created += new FileSystemEventHandler(OnCreated);
    Deleted += new FileSystemEventHandler(OnDeleted);
    Changed += new FileSystemEventHandler(OnChanged);
    Renamed += new RenamedEventHandler(OnRenamed);

On both Windows and Mono/OS X, I tried renaming `file.txt` to `file2.txt` at the root of the watched folder.

Works great: I receive one Renamed (name=file2.txt oldName=file.txt).

Unfortunately I receive 3 events:
1. Changed: file.txt
2. Created: file2.txt
3. Deleted: file.txt

Same result with Environment.SetEnvironmentVariable("MONO_MANAGED_WATCHER", "enabled");

This is problematic for my sync software: syncing deletion/creation to remote is inefficient and looses precious file metadata.