LockAsync Method
LockAsync(TKey)
Locks an entry.
Declaration
Task LockAsync(TKey key)
Parameters
TKey | key | The key identifying the entry. |
Returns
Task | A task that will complete when the lock has been acquired. |
Remarks
If the lock is already owned by another owner, this will wait indefinitely until the lock can be acquired.
Locks are re-entrant, but counted: if a key is locked N times, then it should be unlocked N times before another thread can lock it.
The lock is automatically released after the server-configured maximum lease time has elapsed.
LockAsync(TKey, TimeSpan)
Locks an entry for a given time duration (lease time),
Declaration
Task LockAsync(TKey key, TimeSpan leaseTime)
Parameters
TKey | key | The key identifying the entry. |
TimeSpan | leaseTime | The lease time. |
Returns
Task | A task that will complete when the lock has been acquired. |
Remarks
If the lock is already owned by another owner, this will wait indefinitely until the lock can be acquired.
Locks are re-entrant, but counted: if an entry is locked N times, then it should be unlocked N times before another owner can lock it.
The lock is automatically released after the specified leaseTime
has elapsed.