/// <inheritdoc />
        protected override async Task <ILockManagerTransaction> BeginTransactionAsync(CancellationToken cancellationToken)
        {
            if (!_initialized)
            {
                lock (_initSync)
                {
                    if (!_initialized)
                    {
                        // Load all active locks and add them to the cleanup task.
                        // This ensures that locks still do expire.
                        var activeLocks = _connection.Table <ActiveLockEntry>().ToList();
                        foreach (var activeLock in activeLocks)
                        {
                            LockCleanupTask.Add(this, activeLock);
                        }

                        _initialized = true;
                    }
                }
            }

            await _semaphore.WaitAsync(cancellationToken);

            _connection.BeginTransaction();
            return(new SQLiteLockManagerTransaction(_connection, _semaphore));
        }
        private void AddLocksToCleanupTask()
        {
            if (!File.Exists(_lockFileName))
            {
                return;
            }

            // Load all active locks and add them to the cleanup task.
            // This ensures that locks still do expire.
            try
            {
                var file        = File.ReadAllText(_lockFileName);
                var activeLocks = JsonConvert.DeserializeObject <ICollection <ActiveLock> >(file);
                foreach (var activeLock in activeLocks)
                {
                    LockCleanupTask.Add(this, activeLock);
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning(0, ex, "Failed to load the lock file: {0}", ex.Message);
            }
        }