2

There are several folders on back-end of Web API server. Each of them is a git repository. Let's call them

  • Project1
  • Project2
  • Project3

How can I create lock on server so only one user (thread) in a project can work with a particular folder? Currently I've implemented simple lock using static object and Monitor class. But in this case access to folders is locked on a global level whereas lock should be applied on each folder independently.

Which .NET threading instrument would be most suitable in my situation?

AlexProutorov
  • 677
  • 11
  • 22

1 Answers1

2

Locking things globally requires a Mutex.

You can give a mutex a globally unique (on the machine) name by using the prefix "Global\" (For example "Global\\project1", "Global\\project2" and "Global\\project3") and see if it's in use by somebody else.

There is a solid thread on how to use one perfectly here.

Community
  • 1
  • 1
nvoigt
  • 75,013
  • 26
  • 93
  • 142