SmartDirWatcher 1.0.2

A Win32 Implementation of a DirWatcher, which should avoid typical problems with the native .NET FileSystemWatcher

Install-Package SmartDirWatcher -Version 1.0.2
dotnet add package SmartDirWatcher --version 1.0.2
<PackageReference Include="SmartDirWatcher" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SmartDirWatcher --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SmartDirWatcher

An alternative to the native .NET FileSystemWatcher which always causes several problems to many users.
This library is based on implementation of W32 API to get system internal file indices. Then an internal object can identify if a file is newly created, changed or deleted.

Implement the SmartDirWatcher

After loading the nuget package the implementation is quite simple.
Just instance an object, connect the eventhandler and start the watcher. You can define watching for a specific file extension or for an explicit filename.

Watch for a extension

Watcher smartWatcher = new Watcher("directory/to/watch/for/files", ".dll", WATCHMODE.Extension);
smartWatcher.DirWatcherEventRaised += OnFolderFilesChanged;
smartWatcher.Start();

Watch for a specific filename

Watcher smartWatcher = new Watcher("directory/to/watch/for/files", "awesome.txt", WATCHMODE.FileName);
smartWatcher.DirWatcherEventRaised += OnFolderFilesChanged;
smartWatcher.Start();

How to handle events.

After an instance of SmartDirWatcher is up and running, everytime something happens within the folder you watching, an event will been fired throug the event handler. Be sure to cast EventArgs to DirWatcherEventArgs to handle the fired event type.
You can then select the event you want to interact with and do whatever you want to.

 protected void OnFolderFilesChanged(object sender, EventArgs e)
        {
            DirWatcherEventArgs args = e as DirWatcherEventArgs;
            switch (args.Type)
            {
                case EventType.Created:
                    // Do something
                    break;
                case EventType.Changed:
                    // Do something
                    break;
                case EventType.Deleted:
                     // Do something
                    break;
            }
        }

SmartDirWatcher

An alternative to the native .NET FileSystemWatcher which always causes several problems to many users.
This library is based on implementation of W32 API to get system internal file indices. Then an internal object can identify if a file is newly created, changed or deleted.

Implement the SmartDirWatcher

After loading the nuget package the implementation is quite simple.
Just instance an object, connect the eventhandler and start the watcher. You can define watching for a specific file extension or for an explicit filename.

Watch for a extension

Watcher smartWatcher = new Watcher("directory/to/watch/for/files", ".dll", WATCHMODE.Extension);
smartWatcher.DirWatcherEventRaised += OnFolderFilesChanged;
smartWatcher.Start();

Watch for a specific filename

Watcher smartWatcher = new Watcher("directory/to/watch/for/files", "awesome.txt", WATCHMODE.FileName);
smartWatcher.DirWatcherEventRaised += OnFolderFilesChanged;
smartWatcher.Start();

How to handle events.

After an instance of SmartDirWatcher is up and running, everytime something happens within the folder you watching, an event will been fired throug the event handler. Be sure to cast EventArgs to DirWatcherEventArgs to handle the fired event type.
You can then select the event you want to interact with and do whatever you want to.

 protected void OnFolderFilesChanged(object sender, EventArgs e)
        {
            DirWatcherEventArgs args = e as DirWatcherEventArgs;
            switch (args.Type)
            {
                case EventType.Created:
                    // Do something
                    break;
                case EventType.Changed:
                    // Do something
                    break;
                case EventType.Deleted:
                     // Do something
                    break;
            }
        }

Release Notes

Fixed a bug where filenames with capital letters where not recognized.

Dependencies

This package has no dependencies.

Version History

Version Downloads Last updated
1.0.2 145 1/8/2019
1.0.1 129 10/12/2018