From d73701c939ec80443c1208563202c0090eedbe2c Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Sat, 3 Jul 2021 20:34:50 -0600 Subject: [PATCH] Stop automatic processing if form is closed instead of crashing. --- .../BookLiberation/AutomatedBackupsForm.cs | 11 ++++++++--- .../BookLiberation/ProcessorAutomationController.cs | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) 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)