Search code examples
c#.netmultithreadingfilesystemwatcher

Does FileSystemWatcher create its own thread?


I want this work to be done in a different thread but do i have to create a thread or does it do all the work on different threads?

Like:

Thread fileThread = new Thread(() =>
{
    FileWatcher = new FileSystemWatcher();

    FileWatcher.Created += OnFileEvent;
    FileWatcher.Deleted += OnFileEvent;
    FileWatcher.Renamed += OnRenameEvent;
    FileWatcher.EnableRaisingEvents = true;
});

fileThread.Start();

Solution

  • You don't have to create a thread. The events will be called on a separate thread automatically.