I'm using SemaphoreSlim to "lock" some of my Web-API's methods until it worked correctly however there are times when these same methods get stuck completely, by postman when I run it gets a loading and after some time returns the error.
Follow the code
public class ApiController : Controller
{
static SemaphoreSlim semaphoreSlimScheduling = new SemaphoreSlim(1);
...//outros métodos
[HttpPost]
public async Task<JsonResult> ConfirmScheduling(FormCollection collection)
{
try
{
await semaphoreSlimScheduling.WaitAsync();
//código....
semaphoreSlimScheduling.Release();
return Json(new { error = false, message = "Sucesso" });
}
catch (Exception ex)
{
semaphoreSlimScheduling.Release();
return Json(new { error = true, message = ex.Message });
}
}
}
Only one other method is using the SemaphoreSlim wait. The other methods I'm not doing this locking. Anyone have an idea what it can be?