Does FileSystemWatcher create its own thread?

syncis picture syncis · Jul 15, 2012 · Viewed 11k times · Source

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();

Answer

Guffa picture Guffa · Jul 15, 2012

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