diff --git a/src/StarfaceOutlookSync/UI/DedupeForm.cs b/src/StarfaceOutlookSync/UI/DedupeForm.cs index 789d57b7..cd992411 100644 --- a/src/StarfaceOutlookSync/UI/DedupeForm.cs +++ b/src/StarfaceOutlookSync/UI/DedupeForm.cs @@ -89,8 +89,31 @@ namespace StarfaceOutlookSync.UI private void AppendLog(string message) { - if (InvokeRequired) { Invoke(new Action(() => AppendLog(message))); return; } - _txtLog.AppendText(message + "\r\n"); + // Der Aufruf kann aus dem Hintergrund kommen, nachdem das Fenster + // bereits geschlossen/entsorgt wurde -> defensiv absichern. + if (IsDisposed || Disposing) return; + try + { + if (InvokeRequired) { BeginInvoke(new Action(() => AppendLog(message))); return; } + if (_txtLog == null || _txtLog.IsDisposed) return; + _txtLog.AppendText(message + "\r\n"); + } + catch (ObjectDisposedException) { } + catch (InvalidOperationException) { } // Handle noch nicht/nicht mehr da + } + + protected override void OnFormClosing(FormClosingEventArgs e) + { + // Nicht schliessen, solange Analyse/Zusammenfuehrung laeuft - sonst + // greifen die Hintergrund-Fortsetzungen auf entsorgte Controls zu. + if (_busy) + { + e.Cancel = true; + _lblSummary.Text = "Bitte warten - der Vorgang laeuft noch..."; + _lblSummary.ForeColor = Color.OrangeRed; + return; + } + base.OnFormClosing(e); } private async Task Analyze()