I'm writing a windows service that might delete a file at some point. Because the service is dealing with regular file IO it's possible that a file can be in use during deletion.
Currently I'm trying to delete and react later when an exception happens. Code looks something like this:
try
{
File.Delete(file);
Status = ResponseStatus.Ok;
}
catch (IOException e)
{
Status = ResponseStatus.FileInUse;
}
finally
{
return Status;
}
How can I determine if a file in use without using an exception?