Class DirectoryWatcher
Track file system events from several directories.
public class DirectoryWatcher : IDisposable
- Inheritance
-
objectDirectoryWatcher
- Implements
- Extension Methods
Constructors
DirectoryWatcher(string?)
Initializes a new instance of the DirectoryWatcher class.
public DirectoryWatcher(string? fileFilter = null)
Parameters
fileFilterstringThe file filter By default null default to .
Properties
FileFilter
Gets the file filter used by this instance.
public string FileFilter { get; }
Property Value
- string
The file filter.
Methods
CreateFileSystemWatcher(string)
protected FileSystemWatcher CreateFileSystemWatcher(string directory)
Parameters
directorystring
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
GetTrackedDirectories()
Gets a list of current directories being tracked.
public List<string> GetTrackedDirectories()
Returns
OnChangesMissed(object, ChangesMissedEventArgs)
Called when the watch of a directory started again after an error.
protected virtual void OnChangesMissed(object sender, ChangesMissedEventArgs e)
Parameters
senderobjectThe sender.
eChangesMissedEventArgsThe directory whose changes may have been missed.
OnModified(object, FileEvent)
Called when a file event occurred.
protected virtual void OnModified(object sender, FileEvent e)
Parameters
senderobjectThe sender.
eFileEventThe file event.
Track(string)
Tracks the specified path.
public void Track(string path)
Parameters
pathstringThe path.
Remarks
If path is a file, this will used the parent directory. If the path is invalid, it will not fail but just skip it.
UnTrack(string)
UnTracks the specified path.
public void UnTrack(string path)
Parameters
pathstring
Remarks
If path is a file, this will used the parent directory. If the path is invalid, it will not fail but just skip it.
Events
ChangesMissed
Occurs when the watch of a directory failed and started again, for example after the buffer of its events overflowed: the changes in that directory in the meantime may never be reported by Modified.
public event EventHandler<ChangesMissedEventArgs>? ChangesMissed
Event Type
Remarks
It is raised once the new watch runs, so a listener that reads the files of the directory again then misses nothing; it can find what changed with a FileWriteTimes.
Modified
Occurs when a file/directory change occurred.
public event EventHandler<FileEvent>? Modified