Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Handle exceptions on saving thread
Browse files Browse the repository at this point in the history
  • Loading branch information
aianlinb authored Sep 26, 2020
1 parent f63122d commit 09dcdbf
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions VisualBundle/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MainWindow()
public void OnUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
var ew = new ErrorWindow();
var t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ew.ShowError))
var t = new Thread(new ParameterizedThreadStart(ew.ShowError))
{
CurrentUICulture = new System.Globalization.CultureInfo("en-US")
};
Expand Down Expand Up @@ -409,18 +409,30 @@ private void OnButtonSaveClick(object sender, RoutedEventArgs e)
ButtonSave.IsEnabled = false;
var sw = new SavingWindow();
var t = new Thread(new ThreadStart(() => {
var i = 1;
var text = "Saving {0} / " + (changed.Count + 1).ToString() + " bundles . . .";
foreach (var br in changed)
try
{
var i = 1;
var text = "Saving {0} / " + (changed.Count + 1).ToString() + " bundles . . .";
foreach (var br in changed)
{
Dispatcher.Invoke(() => { sw.TextBlock1.Text = string.Format(text, i); });
br.Save(br.Name);
i++;
}
Dispatcher.Invoke(() => { sw.TextBlock1.Text = string.Format(text, i); });
br.Save(br.Name);
i++;
ic.Save("_.index.bin");
sw.Closing -= sw.OnClosing;
Dispatcher.Invoke(sw.Close);
} catch (Exception ex)
{
var ew = new ErrorWindow();
var tr = new Thread(new ParameterizedThreadStart(ew.ShowError))
{
CurrentUICulture = new System.Globalization.CultureInfo("en-US")
};
tr.Start(ex);
Dispatcher.Invoke(() => { if (ew.ShowDialog() != true) Close(); });
}
Dispatcher.Invoke(() => { sw.TextBlock1.Text = string.Format(text, i); });
ic.Save("_.index.bin");
sw.Closing -= sw.OnClosing;
Dispatcher.Invoke(sw.Close);
}));
t.Start();
sw.ShowDialog();
Expand Down

0 comments on commit 09dcdbf

Please sign in to comment.