Make cover loading thread save (Just DB part!!!)
This commit is contained in:
1 parent
e1f4b93d03
commit
542c8a5b37
1 file changed
+21
-3
@@ -53,6 +53,8 @@ namespace Vocaluxe.Base
|
||||
private static string _CoverFilePath;
|
||||
private static string _CreditsRessourcesFilePath;
|
||||
|
||||
//You have to lock all actions using cover connection or transaction, otherwhise order is not guaranted
|
||||
private static readonly object _CoverMutex = new object();
|
||||
private static SQLiteConnection _ConnectionCover;
|
||||
private static SQLiteTransaction _TransactionCover;
|
||||
|
||||
@@ -77,7 +79,6 @@ namespace Vocaluxe.Base
|
||||
CLog.LogError("Error initializing Credits-DB", true, true);
|
||||
return false;
|
||||
}
|
||||
GC.Collect();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1059,6 +1060,8 @@ namespace Vocaluxe.Base
|
||||
return false;
|
||||
}
|
||||
|
||||
lock (_CoverMutex)
|
||||
{
|
||||
if (_ConnectionCover == null)
|
||||
{
|
||||
_ConnectionCover = new SQLiteConnection {ConnectionString = "Data Source=" + _CoverFilePath};
|
||||
@@ -1164,21 +1167,35 @@ namespace Vocaluxe.Base
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void CommitCovers()
|
||||
{
|
||||
lock (_CoverMutex)
|
||||
{
|
||||
_CommitCovers();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// You have to hold the CoverMutex when calling this!
|
||||
/// </summary>
|
||||
private static void _CommitCovers()
|
||||
{
|
||||
if (_TransactionCover != null)
|
||||
{
|
||||
_TransactionCover.Commit();
|
||||
_TransactionCover.Dispose();
|
||||
_TransactionCover = null;
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
//Do commit and close atomicly otherwhise we may loose changes
|
||||
lock (_CoverMutex)
|
||||
{
|
||||
CommitCovers();
|
||||
|
||||
@@ -1188,6 +1205,7 @@ namespace Vocaluxe.Base
|
||||
_ConnectionCover = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool _InitCoverDB()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user