C# windows 7 file locks where file is located on a network
I've been having an intermittent issue with files located on a network that I am trying to delete. I'll run into an exception where it says the file cannot be deleted because it's in use by another application.
When I try to delete it manually from the network it gives me the same error. However, when I walk 2 feet away to another computer, logged in as a different account, i'll browse to the same location and the file will not be there at all indicating that it deleted, but must be still in use from some indexing service.
A colleague mentioned something about the windows search service and how it indexes stuff. I disabled that and ended the SearchIndexer.exe process. That worked for a few times and then it started to reoccur randomly.
I can end my explorer.exe process and re-run it, then manually delete the files no problem.
It occurs when I do a Directory.Delete with recursion set to true. The majority of the time it happens with the Thumbs.db file, so it ends up not deleting the directory at all and i'm forced to end my explorer.exe and restart it in order to delete the directory.
My question is, if the file gets deleted from the network but doesn't display as deleted on my computer, how do I prevent it from getting locked in my explorer process?
Re: C# windows 7 file locks where file is located on a network
In some cases yes. The files are copied to the network, and it's possible the user can re-copy them to the same directory depending on certain business circumstances.
In otherwords, they've opened the application, copied the files, rec'd a new CD with different data but same images. When it goes to delete the directory that they were copied too, it throws an exception when trying to delete the thumbs.db file. In most cases it will delete all the images but not the directory.
Here's the method I use, there's some logic that determines when this method is called, but the exception is caught in this method: