Skip to content

AcquireDatabaseLockAsync Method ​

Definition ​

  • Namespace: JASE.Database
  • Assembly: JASE.Database.dll

Task<bool> AcquireDatabaseLockAsync(string resource, DatabaseLockMode mode, DatabaseLockOwner owner, TimeSpan? timeout = null, CancellationToken cancellationToken = null) ​

csharp
Task<bool> AcquireDatabaseLockAsync(string resource, DatabaseLockMode mode, DatabaseLockOwner owner, TimeSpan? timeout = null, CancellationToken cancellationToken = null)

Attempts to acquire a database-backed application lock.

Parameters ​

NameDescription
cancellationTokenToken observed before each non-blocking acquisition attempt and while waiting between attempts. A completed acquisition attempt wins over cancellation so its lock can be tracked safely.
modeRequested shared or exclusive access.
ownerSession or transaction lifetime owner.
resourceProvider-independent lock resource name, limited to 255 characters.
timeoutMaximum time to wait. A value of waits indefinitely, Zero makes one immediate attempt.

Returns ​

when acquired; otherwise after timeout.

Remarks ​

Transaction ownership requires an active transaction. Session-owned locks retain the underlying database connection and should only be used for short-lived coordination.