Ver código fonte

Fixed exception handling for Progress ShowModal

Kenric Nugteren 1 ano atrás
pai
commit
34c99f8a74

+ 4 - 1
inabox.wpf/DynamicGrid/Editors/DocumentEditor/DocumentConfirm.xaml.cs

@@ -6,6 +6,9 @@ using System.IO;
 using System.Reactive;
 using System.Windows;
 using InABox.WPF;
+using InABox.Clients;
+using System.Linq;
+using System.Diagnostics.CodeAnalysis;
 
 namespace InABox.DynamicGrid
 {
@@ -68,7 +71,7 @@ namespace InABox.DynamicGrid
 
         public static Document? CheckDocument(Document newDocument, Func<string, Document?>? findDocument, out bool shouldSave)
         {
-            Document existing = null;
+            Document? existing = null;
             
             using (new WaitCursor())
                 existing = findDocument?.Invoke(newDocument.FileName);

+ 17 - 1
inabox.wpf/ProgressWindow/Progress.cs

@@ -96,6 +96,8 @@ namespace InABox.WPF
 
         public static void ShowModal(string message, Action<IProgress<string>> work)
         {
+            Exception? exception = null;
+
             var progress = new ProgressForm
             {
                 DisplayImage = DisplayImage
@@ -111,13 +113,27 @@ namespace InABox.WPF
                     worker.CancelAsync();
                 };
 
-                worker.DoWork += (o, e) => work(update);
+                worker.DoWork += (o, e) =>
+                {
+                    try
+                    {
+                        work(update);
+                    }
+                    catch (Exception ex)
+                    {
+                        exception = ex;
+                    }
+                };
                 worker.RunWorkerCompleted +=
                     (o, e) => progress.Close();
                 worker.RunWorkerAsync();
             };
 
             progress.ShowDialog();
+            if(exception is not null)
+            {
+                throw exception;
+            }
         }
 
         public static void Show(string message)