when deleting files one by one error is generated as \"the process cannot access the file \' because it is being used by another process when trying to delete file\"
cod
If the file is in use you cannot delete it. However, if you for some reason really want to delete it and you are unable to stop the process that is locking the file (like when uninstalling an application) you can schedule the file for deletion the next time the operating system is restarted. These scheduled deletions are performed before any process is able to lock the file.
You have to use the MoveFileEx Windows API using a null new file name and the flag MOVEFILE_DELAY_UNTIL_REBOOT
. How to do that from C# is explained in an answer to the Stack Overflow question “MoveFile” function in C# (Delete file after reboot) C#.