Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a folder asynchronously

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

like image 433
stackoverflowuser Avatar asked Feb 02 '23 09:02

stackoverflowuser


1 Answers

I would use the Task Parallel Library:

Task.Factory.StartNew(path => Directory.Delete((string)path, true), fullPath);
like image 140
vcsjones Avatar answered Feb 06 '23 12:02

vcsjones