I\'ve written a controller and action that I use as a service. This service runs quite a costly action. I\'d like to limit the access to this action if there is already a cu
Having read and agreed with the above answer I wanted a slightly different solution: If you want to detect a second call to an action, use Monitor.TryEnter:
if (!Monitor.TryEnter(Lock, new TimeSpan(0)))
{
throw new ServiceBusyException("Locked!");
}
try
{
...
}
finally {
Monitor.Exit(Lock);
}
Use the same static Lock object as detailed by @danludwig