我希望这项工作在不同的线程来完成,但我一定要创建一个线程,或者它做所有的工作在不同的线程?
像:
发fileThread =新主题(()=>
{
FileWatcher =新FileSystemWatcher的();
FileWatcher.Created + = OnFileEvent;
FileWatcher.Deleted + = OnFileEvent;
FileWatcher.Renamed + = OnRenameEvent;
FileWatcher.EnableRaisingEvents = TRUE;
});
fileThread.Start();
解决方案
您不必创建一个线程。该事件将被称为在一个单独的线程自动。
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();
解决方案
You don't have to create a thread. The events will be called on a separate thread automatically.