本文介绍了难道FileSystemWatcher的创建自己的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这项工作在不同的线程来完成,但我一定要创建一个线程,或者它做所有的工作在不同的线程?

像:

 发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.

这篇关于难道FileSystemWatcher的创建自己的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 00:53