We have a recurring problem where a (long-running) service throws an
exception while trying to access a file. The problem is that this is
very rare (happens once every week and without warning) but does happen
time to time. We are trying ways to find which other process is holding
on to the file or even if any other thread from our process is holding
on to the file at the specific time that the problem occurs.
So, I am trying to invesitigate whether there are any ways that when we
throw an exception that "The file is in use ...", specifically WHICH
process is holding on to it. i.e. which process is locking the file or
using it. As I was saying, this is a rarely occuring phenomenon and
Process Explorer is not of much use to us as it (as far as I know) does
not have a monitoring mode.
Can anyone please let me know how this can be accomplished in code (C#,
C, C++ .... doesn't matter) ?
- K