Пример #1
0
        /// <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("(-)");
        }
Пример #2
0
        /// <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("(-)");
        }
Пример #3
0
        /// <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("(-)");
        }
Пример #4
0
        /// <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();

            log.Trace("(-)");
            return(result);
        }
Пример #5
0
        /// <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();

            log.Trace("(-)");
            return(result);
        }