/// <summary> /// Releases an acquired lock. /// </summary> /// <param name="Lock">Lock object to release.</param> public void ReleaseLock(DatabaseLock Lock) { log.Trace("(Lock:{0})", Lock); Lock.Lock.Release(); log.Trace("(-)"); }
/// <summary> /// Asynchronously acquires a lock to prevent race conditions. /// </summary> /// <param name="Lock">Lock object to acquire.</param> /// <remarks>The caller is responsible for releasing the lock by calling ReleaseLock.</remarks> public async Task AcquireLockAsync(DatabaseLock Lock) { log.Trace("(Lock:{0})", Lock); await Lock.Lock.WaitAsync(); log.Trace("(-)"); }
/// <summary> /// Acquires a lock to prevent race conditions. /// </summary> /// <param name="Lock">Lock object to acquire.</param> /// <remarks>The caller is responsible for releasing the lock by calling ReleaseLock.</remarks> public void AcquireLock(DatabaseLock Lock) { log.Trace("(Lock:{0})", Lock); Lock.Lock.Wait(); log.Trace("(-)"); }
/// <summary> /// Starts database transaction and acquires a lock. /// The transaction makes sure the whole operation is atomic, /// the lock is used to prevent race conditions among threads. /// </summary> /// <param name="Lock">Lock to protect the transaction.</param> /// <returns>Entity Framework transaction object.</returns> /// <remarks>The caller is responsible for releasing the lock by calling ReleaseLock.</remarks> public IDbContextTransaction BeginTransactionWithLock(DatabaseLock Lock) { log.Trace("(Lock:{0})", Lock); Lock.Lock.Wait(); IDbContextTransaction result = Context.Database.BeginTransaction(IsolationLevel.Serializable); log.Trace("(-)"); return(result); }
/// <summary> /// Asynchronously starts database transaction and acquires a lock. /// The transaction makes sure the whole operation is atomic, /// the lock is used to prevent race conditions among threads. /// </summary> /// <param name="Lock">Lock to protect the transaction.</param> /// <returns>Entity Framework transaction object.</returns> /// <remarks>The caller is responsible for releasing the lock by calling ReleaseLock.</remarks> public async Task <IDbContextTransaction> BeginTransactionWithLockAsync(DatabaseLock Lock) { log.Trace("(Lock:{0})", Lock); await Lock.Lock.WaitAsync(); IDbContextTransaction result = await Context.Database.BeginTransactionAsync(IsolationLevel.Serializable); log.Trace("(-)"); return(result); }