[Mono-osx] FileSystemWatcher workaround for Mac OS X

Kevin Heeney koheeney at gmail.com
Wed Oct 22 00:27:17 EDT 2008


Attached is a FileSystemWatcher class that I wrote to use instead of Mono's
FileSystemWatcher in System.IO for Mac OS X (at least Tiger). I have not
tried, but I believe the FileSystemWatcher supplied with mono may work with
Leopard since Leopard adds a feature called FSEvents. The FileSystemWatcher
in Mono on Mac does not catch most onChanged events for files edited by the
user; though it does seem to catch most onCreated and onDeleted. I noticed
the bug posted on the Mono site, but the Priority was P5 (none), so I had to
come up with an alternative. This solution is not great, but I am sending it
out there for anyone who may need a FileSystemWatcher for Mac. It is
intended to be a drop in replacement for the System.IO.FileSystemWatcher so
hopefully it won't require any code changes.

This implementation is different than the typical Windows/.NET method in
that it does not rely on the OS or any File System Events from the OS.
Instead, it 'samples' the folder to watch at a given interval
[TimerInterval] and then compares to the last sample. That said, this method
has more overhead than the File System Events concept and therefore may not
be good for large folders. On the upside, it is OS independent and so can be
used as a fallback for some OS's like Tiger.


 What is different from Windows implementation:

   -

   Directories do not raise OnChanged() for 'LastAccess'. This is because
   this routine was accessing the folders and changing the LastAccess Date.
   -

   Rename is not supported. For renamed items, you will get separate deleted
   and a created events.
   -

   Internal BufferSize is ignored. The property is there to not break
   existing code.
   -

   Does not raise 'as many' changed events as System.IO.FileSystemWatcher on
   Windows. Windows implementation may raise 3 events for 1 save of a file.
   This method raises 1. I prefer this method more, but it is a difference
   worth noting.
   - Added property [TimerInterval] which takes the interval in milliseconds
   between samples.  This is how often the folder is *checked *for changes.
   Default is 1000 (1 sec)


 Disclaimer: I am sure there is a bug or many. This is posted to offer one
approach for people interested to build on. I am using this class and will
continue to test and tweak. If you want me to send you any fixes, shoot me
an email.


 Mono bug this is in response to:
https://bugzilla.novell.com/show_bug.cgi?id=428270      and
http://www.mail-archive.com/mono-bugs@lists.ximian.com/msg53866.html


 Thanks,

Kevin Heeney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20081021/860934ff/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FileSystemWatcher.zip
Type: application/zip
Size: 20522 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-osx/attachments/20081021/860934ff/attachment-0001.zip 


More information about the Mono-osx mailing list