Browse Source

removed message window call code duplicate

Veloe 2 years ago
parent
commit
df59b3a79a
1 changed files with 13 additions and 35 deletions
  1. 13 35
      VeloeMinecraftLauncher/ViewModels/ViewModelBase.cs

+ 13 - 35
VeloeMinecraftLauncher/ViewModels/ViewModelBase.cs

@@ -80,49 +80,27 @@ public class ViewModelBase : ReactiveValidationObject
                 break;
         }       
 
-#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
-        Dispatcher.UIThread.InvokeAsync(() =>
-        {
-        if (Application.Current is not null && Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
-            {
-                Dispatcher.UIThread.InvokeAsync(() =>
-                {
-                    var ErrorMessageViewModel = new MessageWindowViewModel(message, "Error message", MessageBoxButtons.Ok, stackTrace, logfile:logfile);
-                    var ErrorMessage = new MessageWindow()
-                    {
-                        DataContext = ErrorMessageViewModel
-                    };
-                    //TODO change it to binding
-                    ErrorMessage.FindControl<TitleBarWindow>("titleBar").TitleText = "Error Message";
-
-                    ErrorMessage.ShowDialog(desktop.MainWindow);
-                });
-            }
-        });
-#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
+        OpenErrorWindow(message, logfile, stackTrace);
     }
 
-    public static void OpenErrorWindow(string message, string logfile = "")
+    public static void OpenErrorWindow(string message, string logfile = "", string stackTrace = "")
     {       
 #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
-        Dispatcher.UIThread.InvokeAsync(() =>
+        if (Application.Current is not null && Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
         {
-            if (Application.Current is not null && Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
+            Dispatcher.UIThread.InvokeAsync(() =>
             {
-                Dispatcher.UIThread.InvokeAsync(() =>
+                var ErrorMessageViewModel = new MessageWindowViewModel(message, "Error message", logfile: logfile);
+                var ErrorMessage = new MessageWindow()
                 {
-                    var ErrorMessageViewModel = new MessageWindowViewModel(message, "Error message", logfile: logfile);
-                    var ErrorMessage = new MessageWindow()
-                    {
-                        DataContext = ErrorMessageViewModel
-                    };
-                    //TODO change it to binding
-                    ErrorMessage.GetControl<TitleBarWindow>("titleBar").TitleText = "Error Message";
+                    DataContext = ErrorMessageViewModel
+                };
+                //TODO change it to binding
+                ErrorMessage.GetControl<TitleBarWindow>("titleBar").TitleText = "Error Message";
                     
-                    ErrorMessage.ShowDialog(desktop.MainWindow);
-                });
-            }
-        });
+                ErrorMessage.ShowDialog(desktop.MainWindow);
+            });
+        }     
 #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
     }
 }