/// <summary> /// Gets the connection asynchronous. /// </summary> /// <param name="writable">if set to <c>true</c> [writable].</param> /// <returns></returns> public async Task <SQLiteParallelConnection> GetConnectionAsync(bool writable) { var ct = PoolCancellationToken.Token; ct.ThrowIfCancellationRequested(); if (writable) { var sw = Stopwatch.StartNew(); await this.writeLock.WaitAsync(ct); // TODO shcarr, Ocassionally i have see that applogger.default is null. I don't think we want to have a static variable for logging globally assigned like this // also becuase this is just performance related metrics, i am adding this null check. if (AppLogger.Default != null) { if (sw.ElapsedMilliseconds > 1000) { AppLogger.Default.WriteWarning("[DB.WAIT.WRITE] Pool lock wait time {0}ms", sw.ElapsedMilliseconds); } else if (sw.ElapsedMilliseconds > 100) { AppLogger.Default.WriteInfo("[DB.WAIT.WRITE] Pool lock wait time {0}ms", sw.ElapsedMilliseconds); } else if (sw.ElapsedMilliseconds > 10) { AppLogger.Default.WriteVerbose("[DB.WAIT.WRITE] Pool lock wait time {0}ms", sw.ElapsedMilliseconds); } } return(SQLiteParallelConnectionCache.Take(this.databasePath, false, ct) ?? CreateNew(this.writeLock, this.databasePath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create)); } var rsw = Stopwatch.StartNew(); await this.readLock.WaitAsync(ct); if (AppLogger.Default != null) { if (rsw.ElapsedMilliseconds > 1000) { AppLogger.Default.WriteWarning("[DB.WAIT.READ] Pool lock wait time {0}ms", rsw.ElapsedMilliseconds); } else if (rsw.ElapsedMilliseconds > 100) { AppLogger.Default.WriteInfo("[DB.WAIT.READ] Pool lock wait time {0}ms", rsw.ElapsedMilliseconds); } else if (rsw.ElapsedMilliseconds > 10) { AppLogger.Default.WriteVerbose("[DB.WAIT.READ] Pool lock wait time {0}ms", rsw.ElapsedMilliseconds); } } return(SQLiteParallelConnectionCache.Take(this.databasePath, true, ct) ?? CreateNew(this.readLock, this.databasePath, SQLiteOpenFlags.ReadOnly)); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!disposing || !SQLiteParallelConnectionCache.IsEnable) { base.Dispose(false); } else { SQLiteParallelConnectionCache.Cache(this.DatabasePath, this); } if (this.connectionLock != null) { this.connectionLock.Release(); } }