I have this piece of code that I am using for updating a record. I want to know how to use SemaphoreSlim if there are multiple await statement in one block of code.
Whether deadlock and recursive locks can occur for the below piece of code, and when it occurs,how to avoid Deadlock and recursive locks when we are using SemaphoreSlim?
SemaphoreSlim writelock = new SemaphoreSlim(1,1);
Public async task AddValueToDB(Valuedto value)
{
try{
await writelock.WaitAsync();
_db.tblAction.add(Valuedto);
await _db.SavechangesAsync();
}
catch(Exception ex){throw ex;}
finally{writelock.Release();}
}
}
Please let me know if you want any more information about my requirement.