Using DelayedFileSystemWatcher sample


See attached file for a sample on how to use DelayedFileSystemWatcher class described in my previous post FileSystemWatcher generates duplicate events – How to workaround


 

Program.cs

Comments (4)

  1. Pedro Rainho says:

    I’m using your class and there is a bug e the property Filter, you have

    public string Filter

    {

               get

               {

                   return this._fileSystemWatcher.Filter;

               }

               set

               {

                   this._fileSystemWatcher.Filter = this.Filter;

       }

    }

    and I think it should be

    public string Filter

    {

               get

               {

                   return this._fileSystemWatcher.Filter;

               }

               set

               {

                   this._fileSystemWatcher.Filter = value;

       }

    }

    to define a filter diferent than *.*…

  2. Yes, that’s true. Your fix is good.

    I’ll update the file and re-upload it.

  3. Rocko says:

    Hi Adrian,

    Great code! I really enjoyed how it is working. However I was trying to use the DelayedEvent class in Windwos Service. When compile I’m getting the following exception in InitializeComponent():

    ((System.ComponentModel.ISupportInitialize)(FileMonitor)).BeginInit();

    Unable to cast object of type ‘DirectoryMonitorService.DelayedFileSystemWatcher’ to type ‘System.ComponentModel.ISupportInitialize. Make sure that the source type is convertible to the destination type.

    I was wondering if you can help in this issue. I’m new in the win service and not sure how to make that conversation.

    Thanks in advance!

    Rocko

  4. The DelayedFileSystemWatcher class was not derived from Component and it does not implement ISupportInitialize. That’s the only difference when compared to FileSystemWatcher class. That’s why you cannot call BeginInit, because there’s no BeginInit method. You can probably try to implement this functionality yourself.

Skip to main content