Possible duplicate:
How to delete a file used by another process?
I have the following C # code, but it throws an exception when calling the Delete method:
var dir = new DirectoryInfo(@"C:\mydirectory\"); dir.Delete(true);
The following exception is thrown:
The process cannot access the file 'C: \ mydirectory' because it is being used by another process.
Is there a way to get it to delete this directory, even if it is being used by another process?
source share