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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user