@@ -148,6 +148,9 @@ public bool TimeExecution {
148
148
149
149
/// <summary>
150
150
/// Closes all connections to all async databases.
151
+ /// You should *never* need to do this.
152
+ /// This is a blocking operation that will return when all connections
153
+ /// have been closed.
151
154
/// </summary>
152
155
public static void ResetPool ( )
153
156
{
@@ -168,9 +171,11 @@ public SQLiteConnectionWithLock GetConnection ()
168
171
/// <summary>
169
172
/// Closes any pooled connections used by the database.
170
173
/// </summary>
171
- public void Close ( )
174
+ public Task CloseAsync ( )
172
175
{
173
- SQLiteConnectionPool . Shared . CloseConnection ( _connectionString , _openFlags ) ;
176
+ return Task . Factory . StartNew ( ( ) => {
177
+ SQLiteConnectionPool . Shared . CloseConnection ( _connectionString , _openFlags ) ;
178
+ } ) ;
174
179
}
175
180
176
181
Task < T > ReadAsync < T > ( Func < SQLiteConnectionWithLock , T > read )
@@ -1285,7 +1290,11 @@ public Entry (SQLiteConnectionString connectionString, SQLiteOpenFlags openFlags
1285
1290
1286
1291
public void Close ( )
1287
1292
{
1288
- Connection . Dispose ( ) ;
1293
+ if ( Connection == null )
1294
+ return ;
1295
+ using ( var l = Connection . Lock ( ) ) {
1296
+ Connection . Dispose ( ) ;
1297
+ }
1289
1298
Connection = null ;
1290
1299
}
1291
1300
}
@@ -1321,28 +1330,32 @@ public SQLiteConnectionWithLock GetConnection (SQLiteConnectionString connection
1321
1330
1322
1331
public void CloseConnection ( SQLiteConnectionString connectionString , SQLiteOpenFlags openFlags )
1323
1332
{
1324
- lock ( _entriesLock ) {
1325
- Entry entry ;
1326
- string key = connectionString . ConnectionString ;
1333
+ var key = connectionString . ConnectionString ;
1327
1334
1335
+ Entry entry ;
1336
+ lock ( _entriesLock ) {
1328
1337
if ( _entries . TryGetValue ( key , out entry ) ) {
1329
1338
_entries . Remove ( key ) ;
1330
- entry . Close ( ) ;
1331
1339
}
1332
1340
}
1341
+
1342
+ entry . Close ( ) ;
1333
1343
}
1334
1344
1335
1345
/// <summary>
1336
1346
/// Closes all connections managed by this pool.
1337
1347
/// </summary>
1338
1348
public void Reset ( )
1339
1349
{
1350
+ List < Entry > entries ;
1340
1351
lock ( _entriesLock ) {
1341
- foreach ( var entry in _entries . Values ) {
1342
- entry . Close ( ) ;
1343
- }
1352
+ entries = new List < Entry > ( _entries . Values ) ;
1344
1353
_entries . Clear ( ) ;
1345
1354
}
1355
+
1356
+ foreach ( var e in entries ) {
1357
+ e . Close ( ) ;
1358
+ }
1346
1359
}
1347
1360
}
1348
1361
0 commit comments