0

I need help to manage access conflicts to a shared file. Let me explain. I have a shared directory. I have a Windows service listening to this directory, each time a file is placed there, the service supports it to process it (send by ftp then delete). Four instances of the service run continuously, each instance runs on a different physical server (the fourth instances do not run on the same server). I would like to know how to lock access to the file if it is handled by one instance so that others do not access it at the same time. In advance thank you

ilkerkaran
  • 4,214
  • 3
  • 27
  • 42
Y. Err.
  • 1
  • 2
  • You might find a way to check if a file is being used here: https://stackoverflow.com/questions/876473/is-there-a-way-to-check-if-a-file-is-in-use – Niklas7 Apr 30 '19 at 06:30
  • by locking the file with this method I can no longer manipulate it with methods such as copyto – Y. Err. Apr 30 '19 at 08:01
  • Don't process the file where it appears - copy it to a second shared location, failing if the file already exists. All four servers can attempt it, but only one will succeed. Whichever one succeeds performs the next step. That's a low-tech solution. Another is query a SQL table looking for a record indicating that the file is being processed, and within a transaction, insert the record if it's not found. Only the instance that successfully inserts the record "wins" and gets to process the file. – Scott Hannen Apr 30 '19 at 13:20
  • Like Access, consider creating a parallel .lck file in the shared directory for the file to be processed - the winner is the one that creates the file, then deletes it after processing. – NetMage Apr 30 '19 at 23:30
  • Thank you all. it helped me a lot. – Y. Err. May 02 '19 at 12:27

0 Answers0