How to delete a folder asynchronously

I have a Windows service running that deletes folders from a network drive. I want to make deletion asynchronous. How can I do that?

Now I go through the catalogs and call

Directory.Delete(fullPath, true);

thank

+5
source share
2 answers

I would use a parallel task library:

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

If you are looping, you can use parallel 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));

+1
source

All Articles