P
pgdown
Hi,
I have several processes accessing files from one folder, but only
one process should ever access each file. Once one process has the
file, no other process should be allowed to access it, even after the
first process is finished with it, except in the case where the first
process crashes. In pseudo code..
* Open file with exclusive lock
* Process file - failure will throw exception, skipping 'Remove
file' step below
* Close file and unlock
* Remove file - to clean up, but also to prevent other processes now
accessing the file
...So far I cannot think of a way of doing this, taking into account
pathological cases like the file being accessed between 'Close file
and unlock' and 'Remove file'. The closest I've come however, is to
use File.Open(.. FileShare.Delete), so I can switch 'Remove file' with
'Close file and unlock', but then there the problem that someone could
come along and delete the file mid-processing.
Is there a possible solution in .NET? A way to keep the file locked
from other processes, and still allow full access in the current
process, or an atomic Unlock-and-Delete operation. It also needs to
work across a Windows file shared network using the UNC
Hope someone can help, I have been unable to find anything specific
on Google.
Thank you,
Kind regards,
Eliott
I have several processes accessing files from one folder, but only
one process should ever access each file. Once one process has the
file, no other process should be allowed to access it, even after the
first process is finished with it, except in the case where the first
process crashes. In pseudo code..
* Open file with exclusive lock
* Process file - failure will throw exception, skipping 'Remove
file' step below
* Close file and unlock
* Remove file - to clean up, but also to prevent other processes now
accessing the file
...So far I cannot think of a way of doing this, taking into account
pathological cases like the file being accessed between 'Close file
and unlock' and 'Remove file'. The closest I've come however, is to
use File.Open(.. FileShare.Delete), so I can switch 'Remove file' with
'Close file and unlock', but then there the problem that someone could
come along and delete the file mid-processing.
Is there a possible solution in .NET? A way to keep the file locked
from other processes, and still allow full access in the current
process, or an atomic Unlock-and-Delete operation. It also needs to
work across a Windows file shared network using the UNC
Hope someone can help, I have been unable to find anything specific
on Google.
Thank you,
Kind regards,
Eliott