Reputation: 229
EDIT I know the file is locked (i.e. I do not need to check if it is locked). Rather, I want to know how long it has been locked for. e.g. 1 hour, 24 hours etc.
Is it possible to determine how long a file has been locked for in C#?
I have an application that executes every 10 mins, and moves some files between directories. If a file is locked by a user then it obviously can't move it, so the application sends a warning email to the user.
I only want the email to be sent once - the application executes every 10 mins so at the moment if the user does not close the file they will receive an email every 10 mins.
Hence I thought I could use how long the file has been open for as an indicator as to whether or not to send an email.
But other solutions are welcome too if anyone has any ideas?
Upvotes: 1
Views: 86
Reputation: 354396
Handles don't carry information about when they were created as far as I know. But you can simply store information on whether this file was locked and who was e-mailed about it during the last script run. If the file is still locked by the same user, then don't send another e-mail.
Upvotes: 2