There are two things you must do:
- Set the
InternalBufferSizemaximum supported value (65536). Your attempt to set it to "8192 * 128" is greater than the maximum supported value specified in the documentation , so you may not have increased the buffer size at all. - Queue events from
FileSystemWatcherto the background thread for processing.
, MSDN. , FileSystemWatcher - , . , , . , , , . , , - FileSystemWatcher , , , , , .
, . -, :
Dispatcher changeDispatcher = null;
ManualResetEvent changeDispatcherStarted = new ManualResetEvent(false);
Action changeThreadHandler = () =>
{
changeDispatcher = Dispatcher.CurrentDispatcher;
changeDispatcherStarted.Set();
Dispatcher.Run();
};
new Thread(() => changeThreadHandler()) { IsBackground = true }.Start();
changeDispatcherStarted.WaitOne();
. . , :
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.InternalBufferSize = 64 * 1024;
watcher.IncludeSubdirectories = false;
, , . , :
watcher.Changed += (sender, e) => changeDispatcher.BeginInvoke(new Action(() => OnChanged(sender, e)));
watcher.Created += (sender, e) => changeDispatcher.BeginInvoke(new Action(() => OnCreated(sender, e)));
watcher.Deleted += (sender, e) => changeDispatcher.BeginInvoke(new Action(() => OnDeleted(sender, e)));
watcher.Renamed += (sender, e) => changeDispatcher.BeginInvoke(new Action(() => OnRenamed(sender, e)));
, , FileSystemWatcher ( , ?), :
watcher.Dispose()
changeDispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
. , , . , . - - ( , , API , , ), . " ", , , , , . , .