I\'m developing an ASP.NET Web Api application with C# and .Net Framework 4.7.
I have a method in a controller that I want to execute only by one thread at a time. In ot
I guess you can lock on different levels, with your approach being one.
I've come across a system (or a web app) that utilizes redis as an external service. In redis we save a key for the request, in your case I guess it could be the name of the method. With this approach we first have an action filter that checks if a lock exists (talking to redis) and then blocks the request.
The good thing with redis is that it's very fast, and let's your specify a timeout at which the key will dissapear. This prevents from being stuck with the lock forever.