Browse Source

Add `ConfigureAwait(false)` and make sure to call `CenterWindowOnScreen`

Ruben 1 year ago
parent
commit
13042feff8

+ 1 - 1
src/PicView.Avalonia/Navigation/ImageIterator.cs

@@ -527,7 +527,7 @@ public sealed class ImageIterator : IDisposable
 
                     while (preloadValue.IsLoading)
                     {
-                        await Task.Delay(20);
+                        await Task.Delay(20).ConfigureAwait(false);
                         lock (_lock)
                         {
                             if (CurrentIndex != index)

+ 2 - 2
src/PicView.Avalonia/Navigation/UpdateImage.cs

@@ -20,7 +20,7 @@ public static class UpdateImage
         PreLoader.PreLoadValue? preLoadValue,
         PreLoader.PreLoadValue? nextPreloadValue = null)
     {
-        preLoadValue ??= await vm.ImageIterator.GetPreLoadValueAsync(index);
+        preLoadValue ??= await vm.ImageIterator.GetPreLoadValueAsync(index).ConfigureAwait(false);
         if (preLoadValue.ImageModel?.Image is null)
         {
             var fileInfo = preLoadValue.ImageModel?.FileInfo ?? new FileInfo(imagePaths[index]);
@@ -29,7 +29,7 @@ public static class UpdateImage
 
         if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
         {
-            nextPreloadValue ??= await vm.ImageIterator.GetNextPreLoadValueAsync();
+            nextPreloadValue ??= await vm.ImageIterator.GetNextPreLoadValueAsync().ConfigureAwait(false);
             if (nextPreloadValue.ImageModel?.Image is null)
             {
                 var fileInfo = nextPreloadValue.ImageModel?.FileInfo ?? new FileInfo(

+ 4 - 3
src/PicView.Avalonia/UI/WindowHelper.cs

@@ -172,6 +172,7 @@ public static class WindowHelper
             vm.IsAutoFit = true;
         }
         SetSize(vm);
+        await Dispatcher.UIThread.InvokeAsync(() => CenterWindowOnScreen(false));
         await SettingsHelper.SaveSettingsAsync().ConfigureAwait(false);
     }
 
@@ -197,7 +198,7 @@ public static class WindowHelper
             vm.IsStretched = true;
         }
         SetSize(vm);
-        vm.ImageViewer.MainImage.InvalidateVisual();
+        await Dispatcher.UIThread.InvokeAsync(() => CenterWindowOnScreen(false));
         await SettingsHelper.SaveSettingsAsync().ConfigureAwait(false);
     }
 
@@ -513,13 +514,13 @@ public static class WindowHelper
         }
         else
         {
-            Dispatcher.UIThread.InvokeAsync(() =>
+            Dispatcher.UIThread.Invoke(() =>
             {
                 desktopMinWidth = desktop.MainWindow.MinWidth;
                 desktopMinHeight = desktop.MainWindow.MinHeight;
                 containerWidth = mainView.Bounds.Width;
                 containerHeight = mainView.Bounds.Height;
-            }, DispatcherPriority.Send).Wait();
+            }, DispatcherPriority.Send);
         }
 
         if (double.IsNaN(containerWidth) || double.IsNaN(containerHeight) || double.IsNaN(width) || double.IsNaN(height))