diff --git a/LibationWinForms/BookLiberation/AutomatedBackupsForm.cs b/LibationWinForms/BookLiberation/AutomatedBackupsForm.cs index f663fe18..485e13be 100644 --- a/LibationWinForms/BookLiberation/AutomatedBackupsForm.cs +++ b/LibationWinForms/BookLiberation/AutomatedBackupsForm.cs @@ -24,13 +24,18 @@ namespace LibationWinForms.BookLiberation InitializeComponent(); } - public void WriteLine(string text) - => logTb.UIThread(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}")); + public void WriteLine(string text) + { + if (!IsDisposed) + logTb.UIThread(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}")); + } public void FinalizeUI() { keepGoingCb.Enabled = false; - logTb.AppendText(""); + + if (!IsDisposed) + logTb.AppendText(""); } private void AutomatedBackupsForm_FormClosing(object sender, FormClosingEventArgs e) => keepGoingCb.Checked = false; diff --git a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index da02e3c2..9703a66e 100644 --- a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -66,9 +66,9 @@ namespace LibationWinForms.BookLiberation (Action unsibscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook, automatedBackupsForm); - automatedBackupsForm.FormClosing += (_, __) => unsibscribeEvents(); - await new BackupLoop(logMe, backupBook, automatedBackupsForm).RunBackupAsync(); + + unsibscribeEvents(); } private static BackupBook getWiredUpBackupBook(EventHandler completedAction) @@ -496,6 +496,9 @@ An error occurred while trying to process this book if (!keepGoing) return; + if (AutomatedBackupsForm.IsDisposed) + break; + if (!AutomatedBackupsForm.KeepGoing) { if (AutomatedBackupsForm.KeepGoingVisible && !AutomatedBackupsForm.KeepGoingChecked)