diff --git a/src/BizHawk.Emulation.Common/Database/Database.cs b/src/BizHawk.Emulation.Common/Database/Database.cs index f064ebf89d..31b8d38a68 100644 --- a/src/BizHawk.Emulation.Common/Database/Database.cs +++ b/src/BizHawk.Emulation.Common/Database/Database.cs @@ -13,8 +13,11 @@ namespace BizHawk.Emulation.Common { public static class Database { - private static Dictionary DB; + static Dictionary DB = new Dictionary(); + /// + /// blocks until the DB is done loading + /// static EventWaitHandle acquire = new EventWaitHandle(false, EventResetMode.ManualReset); private static string RemoveHashType(string hash) @@ -91,8 +94,6 @@ namespace BizHawk.Emulation.Common static void initializeWork(string path) { //reminder: this COULD be done on several threads, if it takes even longer - Dictionary db = new Dictionary(); - using var reader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)); while (reader.EndOfStream == false) { @@ -142,13 +143,13 @@ namespace BizHawk.Emulation.Common }; #if DEBUG - if (db.ContainsKey(game.Hash)) + if (DB.ContainsKey(game.Hash)) { Console.WriteLine("gamedb: Multiple hash entries {0}, duplicate detected on \"{1}\" and \"{2}\"", game.Hash, game.Name, DB[game.Hash].Name); } #endif - db[game.Hash] = game; + DB[game.Hash] = game; } catch { @@ -158,7 +159,7 @@ namespace BizHawk.Emulation.Common //commit the finished database load //it's left as null until now to help catch mistakes in using the resource - DB = db; + DB = DB; acquire.Set(); }