I have a windows service running that deletes folders from network drive. I want to make the deleting asynchronous. How can this be done?
Right now i am looping through the directories and calling
Directory.Delete(fullPath, true);
Thanks
I have a windows service running that deletes folders from network drive. I want to make the deleting asynchronous. How can this be done?
Right now i am looping through the directories and calling
Directory.Delete(fullPath, true);
Thanks
I would use the Task Parallel Library:
Task.Factory.StartNew(path => Directory.Delete((string)path, true), fullPath);
If you are looping, you could use a 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));