/// <summary> /// Attempts to update log in parallel with message and adds a time stamp. /// </summary> public void TryWriteToLogStart(string message) { if (Accessible) { message = $"[{DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss:ms")}] {message}"; taskPool.EnqueueTask(() => { BvException exception = logFile.TryAppend(message); if (exception != null) { taskPool.EnqueueAction(() => TryWriteToLogFinish(false)); throw exception; } else { taskPool.EnqueueAction(() => TryWriteToLogFinish(true)); } }); } }
/// <summary> /// Loads the current configuration in parallel. /// </summary> public void LoadStart(ConfigDataCallback UpdateConfig, bool silent = false) { if (!SaveInProgress) { SaveInProgress = true; if (!silent) { Main.SendChatMessage("Loading configuration..."); } taskPool.EnqueueTask(() => { ConfigData cfg; BvException loadException, saveException; loadException = TryLoad(out cfg); cfg = ValidateConfig(cfg); taskPool.EnqueueAction(() => UpdateConfig(cfg)); saveException = TrySave(cfg); if (loadException != null) { loadException = TrySave(cfg); taskPool.EnqueueAction( () => LoadFinish(false, silent)); if (saveException != null) { BvMain.Log.TryWriteToLog(loadException.ToString() + "\n" + saveException.ToString()); taskPool.EnqueueAction(() => Main.SendChatMessage("Unable to load or create configuration file.")); } } else { taskPool.EnqueueAction(() => LoadFinish(true, silent)); } }); } else { Main.SendChatMessage("Save operation already in progress."); } }