public void Dispose(bool destroy) { IDatabaseStore sysdbStore = null; foreach (KeyValuePair <String, IDatabaseStore> pair in _databases) { if (pair.Value is SystemDatabaseStore) { sysdbStore = pair.Value; // dispose it at the end } else if (pair.Value != null) { pair.Value.Dispose(destroy); } } if (sysdbStore != null) { sysdbStore.Dispose(destroy); } }