如何异步删除文件夹



我有一个正在运行的windows服务,它可以从网络驱动器中删除文件夹。我想使删除异步。如何做到这一点?

现在我正在循环浏览目录并调用

Directory.Delete(fullPath, true);

感谢

我会使用任务并行库:

Task.Factory.StartNew(path => Directory.Delete((string)path, true), fullPath);

如果循环,可以使用并行的foreach

// assuming that you have a list string paths.  
// also assuming that it does not matter what order in which you delete them
Parallel.ForEach(theListOfDirectories, x => Directory.Delete(x));

最新更新