TryLockAsync Method
TryLockAsync(TKey)
Tries to lock an entry immediately.
Declaration
Task<bool> TryLockAsync(TKey key)
Parameters
TKey | key | The key identifying the entry. |
Returns
Task<Boolean> |
|
Remarks
If the entry cannot be locked, returns false
immediately.
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 server-configured maximum lease time has elapsed.
TryLockAsync(TKey, TimeSpan)
Tries to lock an entry within a server-side timeout.
Declaration
Task<bool> TryLockAsync(TKey key, TimeSpan timeToWait)
Parameters
TKey | key | The key identifying the entry. |
TimeSpan | timeToWait | How long to wait for the lock (-1ms to wait forever; 0ms to not wait at all). |
Returns
Task<Boolean> |
|
Remarks
If the entry cannot be locked after timeToWait
has elapsed, returns false
.
If timeToWait
is -1ms, waits forever. If it is 0ms, does not wait at all.
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 server-configured maximum lease time has elapsed.
TryLockAsync(TKey, TimeSpan, TimeSpan)
Tries to lock an entry for a given time duration (lease time), within a server-side timeout.
Declaration
Task<bool> TryLockAsync(TKey key, TimeSpan timeToWait, TimeSpan leaseTime)
Parameters
TKey | key | The key identifying the entry. |
TimeSpan | timeToWait | How long to wait for the lock (-1ms to wait forever; 0ms to not wait at all). |
TimeSpan | leaseTime | The lease time. |
Returns
Task<Boolean> |
|
Remarks
If the entry cannot be locked after timeToWait
has elapsed, returns false
.
If timeToWait
is -1ms, waits forever. If it is 0ms, does not wait at all.
The lock is automatically released after the specified leaseTime
has elapsed.
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.