Fix DedupeForm crash when closed during run (ObjectDisposedException)

Wurde das Dubletten-Fenster geschlossen, waehrend Analyse/Zusammenfuehrung
noch lief, griff die Hintergrund-Fortsetzung auf das entsorgte Textfeld zu
-> ObjectDisposedException im async-void Handler -> App-Absturz.

- AppendLog ist jetzt disposed-sicher (IsDisposed/Disposing-Check, BeginInvoke,
  ObjectDisposedException/InvalidOperationException abgefangen).
- OnFormClosing verhindert das Schliessen, solange _busy (Analyse/Merge laeuft),
  sodass keine Fortsetzung auf entsorgte Controls trifft.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-17 14:16:23 +02:00
co-authored by Claude Opus 4.8
parent 0076d84062
commit e7a87fbdf1
+24 -1
View File
@@ -89,9 +89,32 @@ namespace StarfaceOutlookSync.UI
private void AppendLog(string message)
{
if (InvokeRequired) { Invoke(new Action(() => AppendLog(message))); return; }
// 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()
{