aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-19 16:27:02 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-19 16:27:02 -0400
commiteb612bd303b1ff7adf44f38496448b6064c465fe (patch)
tree6e95bf2d63aa0ebb296c09c37ccb03bd1b9212aa /MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
parent6c1bfe661bf2d0c2e988793bd760148d57014bb4 (diff)
fixed db disposals
Diffstat (limited to 'MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs45
1 files changed, 24 insertions, 21 deletions
diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
index 6824442f1..6179af1cb 100644
--- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
+++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
@@ -160,27 +160,30 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{
try
{
- if (connection != null)
+ lock (this)
{
- if (EnableDelayedCommands)
+ if (connection != null)
{
- FlushOnDispose();
+ if (EnableDelayedCommands)
+ {
+ FlushOnDispose();
+ }
+
+ if (connection.IsOpen())
+ {
+ connection.Close();
+ }
+
+ connection.Dispose();
+ connection = null;
}
-
- if (connection.IsOpen())
+
+ if (FlushTimer != null)
{
- connection.Close();
+ FlushTimer.Dispose();
+ FlushTimer = null;
}
-
- connection.Dispose();
- }
-
- if (FlushTimer != null)
- {
- FlushTimer.Dispose();
- FlushTimer = null;
}
-
}
catch (Exception ex)
{
@@ -195,13 +198,13 @@ namespace MediaBrowser.Server.Implementations.Sqlite
private void FlushOnDispose()
{
// If we're not already flushing, do it now
- if (!IsFlushing)
+ if (!_isFlushing)
{
Flush(null);
}
// Don't dispose in the middle of a flush
- while (IsFlushing)
+ while (_isFlushing)
{
Thread.Sleep(25);
}
@@ -225,7 +228,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// <summary>
/// The is flushing
/// </summary>
- private bool IsFlushing;
+ private bool _isFlushing;
/// <summary>
/// Flushes the specified sender.
@@ -241,12 +244,12 @@ namespace MediaBrowser.Server.Implementations.Sqlite
return;
}
- if (IsFlushing)
+ if (_isFlushing)
{
return;
}
- IsFlushing = true;
+ _isFlushing = true;
var numCommands = 0;
using (var tran = connection.BeginTransaction())
@@ -278,7 +281,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
Logger.Debug("SQL Delayed writer executed " + numCommands + " commands");
FlushTimer.Change(TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1));
- IsFlushing = false;
+ _isFlushing = false;
}
/// <summary>