浏览代码

Code refactoring and improved startup behaviour

Ruben 5 年之前
父节点
当前提交
ccf064d5fd
共有 32 个文件被更改,包括 238 次插入243 次删除
  1. 4 34
      PicView/ChangeImage/Error_Handling.cs
  2. 2 2
      PicView/ChangeImage/GoToLogic.cs
  3. 1 1
      PicView/ChangeImage/LoadFromWeb.cs
  4. 25 36
      PicView/ChangeImage/Navigation.cs
  5. 10 9
      PicView/FileHandling/Copy-paste.cs
  6. 5 4
      PicView/FileHandling/Open_Save.cs
  7. 3 3
      PicView/FileHandling/RecentFiles.cs
  8. 48 0
      PicView/ImageHandling/DisplayUnsupportedImage.cs
  9. 11 4
      PicView/ImageHandling/Thumbnails.cs
  10. 1 1
      PicView/Shortcuts/GotoPicsShortcuts.cs
  11. 1 1
      PicView/SystemIntegration/NativeMethods.cs
  12. 2 1
      PicView/SystemIntegration/Wallpaper.cs
  13. 20 4
      PicView/UI/Animations/AnimationHelper.cs
  14. 2 1
      PicView/UI/Animations/FadeControls.cs
  15. 5 5
      PicView/UI/DragAndDrop.cs
  16. 11 12
      PicView/UI/Loading/EventsHandling.cs
  17. 15 15
      PicView/UI/Loading/LoadContextMenus.cs
  18. 17 8
      PicView/UI/Loading/StartLoading.cs
  19. 13 8
      PicView/UI/PicGallery/GalleryClick.cs
  20. 4 3
      PicView/UI/PicGallery/GalleryFunctions.cs
  21. 1 1
      PicView/UI/PicGallery/GalleryToggle.cs
  22. 4 1
      PicView/UI/Tooltip.cs
  23. 6 0
      PicView/UI/TransformImage/Zoom.cs
  24. 3 2
      PicView/UI/UpdateUIValues.cs
  25. 7 7
      PicView/UI/UserControls/Buttons/ClickArrow.xaml.cs
  26. 6 6
      PicView/UI/UserControls/Buttons/Minus.xaml.cs
  27. 1 1
      PicView/UI/UserControls/Gallery/PicGallery.xaml.cs
  28. 1 1
      PicView/UI/UserControls/Menus/QuickSettingsMenu.xaml
  29. 1 1
      PicView/UI/UserControls/Menus/QuickSettingsMenu.xaml.cs
  30. 0 55
      PicView/UI/UserControls/Misc/BadImage.xaml
  31. 0 15
      PicView/UI/UserControls/Misc/BadImage.xaml.cs
  32. 8 1
      PicView/UI/UserControls/UC.cs

+ 4 - 34
PicView/ChangeImage/Error_Handling.cs

@@ -33,7 +33,7 @@ namespace PicView.ChangeImage
 #endif
 #endif
             if (Pics == null)
             if (Pics == null)
             {
             {
-                Reload(true);
+                await Reload(true).ConfigureAwait(true);
                 return null;
                 return null;
             }
             }
 
 
@@ -172,7 +172,7 @@ namespace PicView.ChangeImage
         /// <summary>
         /// <summary>
         /// Refresh the current list of pics and reload them if there is some missing or changes.
         /// Refresh the current list of pics and reload them if there is some missing or changes.
         /// </summary>
         /// </summary>
-        internal static void Reload(bool fromBackup = false)
+        internal static async Task Reload(bool fromBackup = false)
         {
         {
             if (fromBackup && string.IsNullOrWhiteSpace(xPicPath))
             if (fromBackup && string.IsNullOrWhiteSpace(xPicPath))
             {
             {
@@ -201,9 +201,8 @@ namespace PicView.ChangeImage
 
 
                 // Need a sort method instead
                 // Need a sort method instead
                 GalleryFunctions.Clear();
                 GalleryFunctions.Clear();
-                GalleryLoad.Load();
 
 
-                Pic(s);
+                await Pic(s).ConfigureAwait(false);
 
 
                 // Reset
                 // Reset
 
 
@@ -223,7 +222,7 @@ namespace PicView.ChangeImage
             }
             }
             else if (Uri.IsWellFormedUriString(s, UriKind.Absolute)) // Check if from web
             else if (Uri.IsWellFormedUriString(s, UriKind.Absolute)) // Check if from web
             {
             {
-                LoadFromWeb.PicWeb(s);
+                await LoadFromWeb.PicWeb(s).ConfigureAwait(false);
             }
             }
             else
             else
             {
             {
@@ -265,34 +264,5 @@ namespace PicView.ChangeImage
             SystemIntegration.Taskbar.NoProgress();
             SystemIntegration.Taskbar.NoProgress();
             AnimationHelper.Fade(ajaxLoading, 0, TimeSpan.FromSeconds(.2));
             AnimationHelper.Fade(ajaxLoading, 0, TimeSpan.FromSeconds(.2));
         }
         }
-
-        /// <summary>
-        /// Display broken image status, without affecting file list
-        /// </summary>
-        internal static void DisplayBrokenImage()
-        {
-            mainWindow.img.Source = null;
-
-            if (badImage == null)
-            {
-                badImage = new UI.UserControls.BadImage
-                {
-                    Width = xWidth,
-                    Height = xHeight
-                };
-            }
-            else
-            {
-                badImage.Width = xWidth;
-                badImage.Height = xHeight;
-            }
-
-            mainWindow.topLayer.Children.Add(badImage);
-
-            mainWindow.Bar.ToolTip = mainWindow.Bar.Text = CannotRender;
-            mainWindow.Title = CannotRender + " - " + AppName;
-
-            IsUnsupported = true;
-        }
     }
     }
 }
 }

+ 2 - 2
PicView/ChangeImage/GoToLogic.cs

@@ -10,14 +10,14 @@ namespace PicView.ChangeImage
 {
 {
     internal static class GoToLogic
     internal static class GoToLogic
     {
     {
-        internal static void GoToPicEvent(object sender, RoutedEventArgs e)
+        internal static async System.Threading.Tasks.Task GoToPicEventAsync(object sender, RoutedEventArgs e)
         {
         {
             if (int.TryParse(quickSettingsMenu.GoToPicBox.Text.ToString(), out int x))
             if (int.TryParse(quickSettingsMenu.GoToPicBox.Text.ToString(), out int x))
             {
             {
                 x--;
                 x--;
                 x = x <= 0 ? 0 : x;
                 x = x <= 0 ? 0 : x;
                 x = x >= Pics.Count ? Pics.Count - 1 : x;
                 x = x >= Pics.Count ? Pics.Count - 1 : x;
-                Navigation.Pic(x);
+                await Navigation.Pic(x).ConfigureAwait(false);
                 quickSettingsMenu.GoToPicBox.Text = (x + 1).ToString(CultureInfo.CurrentCulture);
                 quickSettingsMenu.GoToPicBox.Text = (x + 1).ToString(CultureInfo.CurrentCulture);
             }
             }
             else
             else

+ 1 - 1
PicView/ChangeImage/LoadFromWeb.cs

@@ -23,7 +23,7 @@ namespace PicView.ChangeImage
         /// Attemps to download image and display it
         /// Attemps to download image and display it
         /// </summary>
         /// </summary>
         /// <param name="path"></param>
         /// <param name="path"></param>
-        internal static async void PicWeb(string path)
+        internal static async Task PicWeb(string path)
         {
         {
             if (ajaxLoading.Opacity != 1)
             if (ajaxLoading.Opacity != 1)
             {
             {

+ 25 - 36
PicView/ChangeImage/Navigation.cs

@@ -31,7 +31,7 @@ namespace PicView.ChangeImage
         /// Loads a picture from a given file path and does extra error checking
         /// Loads a picture from a given file path and does extra error checking
         /// </summary>
         /// </summary>
         /// <param name="path"></param>
         /// <param name="path"></param>
-        internal static async void Pic(string path)
+        internal static async Task Pic(string path)
         {
         {
             // Set Loading
             // Set Loading
             mainWindow.Title = mainWindow.Bar.Text = Loading;
             mainWindow.Title = mainWindow.Bar.Text = Loading;
@@ -46,7 +46,7 @@ namespace PicView.ChangeImage
             {
             {
                 if (Uri.IsWellFormedUriString(path, UriKind.Absolute))
                 if (Uri.IsWellFormedUriString(path, UriKind.Absolute))
                 {
                 {
-                    LoadFromWeb.PicWeb(path);
+                    await LoadFromWeb.PicWeb(path).ConfigureAwait(false);
                     return;
                     return;
                 }
                 }
                 else if (Directory.Exists(path))
                 else if (Directory.Exists(path))
@@ -89,7 +89,7 @@ namespace PicView.ChangeImage
                     if (!recovery)
                     if (!recovery)
                     {
                     {
                         ShowTooltipMessage("Archive could not be processed");
                         ShowTooltipMessage("Archive could not be processed");
-                        Reload(true);
+                        await Reload(true).ConfigureAwait(false);
                         return;
                         return;
                     }
                     }
                     else
                     else
@@ -102,7 +102,7 @@ namespace PicView.ChangeImage
             }
             }
             else
             else
             {
             {
-                Reload(true);
+                await Reload(true).ConfigureAwait(false);
                 return;
                 return;
             }
             }
 
 
@@ -117,9 +117,7 @@ namespace PicView.ChangeImage
 #endif
 #endif
 
 
             // Navigate to picture using obtained index
             // Navigate to picture using obtained index
-            Pic(FolderIndex);
-
-            quickSettingsMenu.GoToPicBox.Text = (FolderIndex + 1).ToString(CultureInfo.CurrentCulture);
+            await Pic(FolderIndex).ConfigureAwait(false);
 
 
             AjaxLoadingEnd();
             AjaxLoadingEnd();
 
 
@@ -130,7 +128,7 @@ namespace PicView.ChangeImage
         /// Loads image based on overloaded int.
         /// Loads image based on overloaded int.
         /// </summary>
         /// </summary>
         /// <param name="x">The index of file to load from Pics</param>
         /// <param name="x">The index of file to load from Pics</param>
-        internal static async void Pic(int x)
+        internal static async Task Pic(int x)
         {
         {
 #if DEBUG
 #if DEBUG
             var stopWatch = new Stopwatch();
             var stopWatch = new Stopwatch();
@@ -139,20 +137,12 @@ namespace PicView.ChangeImage
 
 
             BitmapSource pic;
             BitmapSource pic;
 
 
-            // Clear unsupported image window, if shown
-            if (IsUnsupported)
-            {
-                mainWindow.topLayer.Children.Remove(badImage);
-                badImage = null;
-                IsUnsupported = false;
-            }
-
             if (Pics.Count <= x)
             if (Pics.Count <= x)
             {
             {
                 pic = await PicErrorFix(x).ConfigureAwait(true);
                 pic = await PicErrorFix(x).ConfigureAwait(true);
                 if (pic == null)
                 if (pic == null)
                 {
                 {
-                    Reload(true);
+                    await Reload(true).ConfigureAwait(false);
                     return;
                     return;
                 }
                 }
             }
             }
@@ -218,9 +208,8 @@ namespace PicView.ChangeImage
                             return;
                             return;
                         }
                         }
 
 
-                        DisplayBrokenImage();
+                        pic = DisplayUnsupportedImage.DrawUnsupportedImageText();
                         CanNavigate = true;
                         CanNavigate = true;
-                        return;
                     }
                     }
                 }
                 }
             }
             }
@@ -243,7 +232,7 @@ namespace PicView.ChangeImage
 
 
             if (Pics.Count > 1)
             if (Pics.Count > 1)
             {
             {
-                SystemIntegration.Taskbar.Progress(x, Pics.Count);
+                Taskbar.Progress(x, Pics.Count);
 
 
                 // Preload images \\
                 // Preload images \\
                 if (Preloader.StartPreload())
                 if (Preloader.StartPreload())
@@ -282,7 +271,7 @@ namespace PicView.ChangeImage
         /// </summary>
         /// </summary>
         /// <param name="pic"></param>
         /// <param name="pic"></param>
         /// <param name="imageName"></param>
         /// <param name="imageName"></param>
-        internal static void Pic(BitmapSource pic, string imageName)
+        internal static void Pic(BitmapSource bitmap, string imageName)
         {
         {
             /// Old method, might need updates?
             /// Old method, might need updates?
 
 
@@ -293,12 +282,12 @@ namespace PicView.ChangeImage
                 mainWindow.Scroller.ScrollToTop();
                 mainWindow.Scroller.ScrollToTop();
             }
             }
 
 
-            mainWindow.img.Source = pic;
+            mainWindow.img.Source = bitmap;
 
 
-            FitImage(pic.PixelWidth, pic.PixelHeight);
+            FitImage(bitmap.PixelWidth, bitmap.PixelHeight);
             CloseToolTipMessage();
             CloseToolTipMessage();
 
 
-            SetTitleString(pic.PixelWidth, pic.PixelHeight, imageName);
+            SetTitleString(bitmap.PixelWidth, bitmap.PixelHeight, imageName);
 
 
             Taskbar.NoProgress();
             Taskbar.NoProgress();
 
 
@@ -310,7 +299,7 @@ namespace PicView.ChangeImage
         /// </summary>
         /// </summary>
         /// <param name="pic"></param>
         /// <param name="pic"></param>
         /// <param name="imageName"></param>
         /// <param name="imageName"></param>
-        internal static async void Pic64(string base64string)
+        internal static async Task Pic64(string base64string)
         {
         {
             var pic = await Base64.Base64StringToBitmap(base64string).ConfigureAwait(true);
             var pic = await Base64.Base64StringToBitmap(base64string).ConfigureAwait(true);
 
 
@@ -333,12 +322,12 @@ namespace PicView.ChangeImage
             CanNavigate = false;
             CanNavigate = false;
         }
         }
 
 
-        internal static void PicFolder(string folder)
+        internal static async Task PicFolderAsync(string folder)
         {
         {
             ChangeFolder(true);
             ChangeFolder(true);
             Pics = FileList(folder);
             Pics = FileList(folder);
 
 
-            Pic(0);
+            await Pic(0).ConfigureAwait(false);
 
 
             quickSettingsMenu.GoToPicBox.Text = (FolderIndex + 1).ToString(CultureInfo.CurrentCulture);
             quickSettingsMenu.GoToPicBox.Text = (FolderIndex + 1).ToString(CultureInfo.CurrentCulture);
 
 
@@ -357,7 +346,7 @@ namespace PicView.ChangeImage
         /// <param name="next">Whether it's forward or not</param>
         /// <param name="next">Whether it's forward or not</param>
         /// <param name="end">Whether to go to last or first,
         /// <param name="end">Whether to go to last or first,
         /// depending on the next value</param>
         /// depending on the next value</param>
-        internal static void Pic(bool next = true, bool end = false)
+        internal static async Task Pic(bool next = true, bool end = false)
         {
         {
             // Exit if not intended to change picture
             // Exit if not intended to change picture
             if (!CanNavigate)
             if (!CanNavigate)
@@ -442,7 +431,7 @@ namespace PicView.ChangeImage
             }
             }
 
 
             // Go to the image!
             // Go to the image!
-            Pic(FolderIndex);
+            await Pic(FolderIndex).ConfigureAwait(true);
 
 
             // Update PicGallery selected item, if needed
             // Update PicGallery selected item, if needed
             if (picGallery != null)
             if (picGallery != null)
@@ -464,7 +453,7 @@ namespace PicView.ChangeImage
             }
             }
         }
         }
 
 
-        internal static void PicButton(bool arrow, bool right)
+        internal static async Task PicButton(bool arrow, bool right)
         {
         {
             if (arrow)
             if (arrow)
             {
             {
@@ -476,12 +465,12 @@ namespace PicView.ChangeImage
                 if (right)
                 if (right)
                 {
                 {
                     ClickArrowRightClicked = true;
                     ClickArrowRightClicked = true;
-                    Pic();
+                    await Pic().ConfigureAwait(false);
                 }
                 }
                 else
                 else
                 {
                 {
                     ClickArrowLeftClicked = true;
                     ClickArrowLeftClicked = true;
-                    Pic(false, false);
+                    await Pic(false, false).ConfigureAwait(false);
                 }
                 }
             }
             }
             else
             else
@@ -500,12 +489,12 @@ namespace PicView.ChangeImage
                 if (right)
                 if (right)
                 {
                 {
                     RightbuttonClicked = true;
                     RightbuttonClicked = true;
-                    Pic();
+                    await Pic().ConfigureAwait(false);
                 }
                 }
                 else
                 else
                 {
                 {
                     LeftbuttonClicked = true;
                     LeftbuttonClicked = true;
-                    Pic(false, false);
+                    await Pic(false, false).ConfigureAwait(false);
                 }
                 }
             }
             }
         }
         }
@@ -567,7 +556,7 @@ namespace PicView.ChangeImage
         /// <summary>
         /// <summary>
         /// Update after FastPic() was used
         /// Update after FastPic() was used
         /// </summary>
         /// </summary>
-        internal static void FastPicUpdate()
+        internal static async Task FastPicUpdate()
         {
         {
             if (!FastPicRunning)
             if (!FastPicRunning)
             {
             {
@@ -582,7 +571,7 @@ namespace PicView.ChangeImage
                 Preloader.Clear();
                 Preloader.Clear();
             }
             }
 
 
-            Pic(FolderIndex);
+            await Pic(FolderIndex).ConfigureAwait(false);
         }
         }
 
 
         #endregion Change navigation values
         #endregion Change navigation values

+ 10 - 9
PicView/FileHandling/Copy-paste.cs

@@ -5,6 +5,7 @@ using System.Diagnostics;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
 using System.Reflection;
 using System.Reflection;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 using static PicView.ChangeImage.Error_Handling;
 using static PicView.ChangeImage.Error_Handling;
@@ -90,7 +91,7 @@ namespace PicView.FileHandling
         /// Retrieves the data from the clipboard and attemps to load image, if possible
         /// Retrieves the data from the clipboard and attemps to load image, if possible
         /// </summary>
         /// </summary>
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "<Pending>")]
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "<Pending>")]
-        internal static void Paste()
+        internal static async Task Paste()
         {
         {
             // file
             // file
 
 
@@ -107,16 +108,16 @@ namespace PicView.FileHandling
                         // If from same folder
                         // If from same folder
                         if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]) && Path.GetDirectoryName(x) == Path.GetDirectoryName(Pics[FolderIndex]))
                         if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]) && Path.GetDirectoryName(x) == Path.GetDirectoryName(Pics[FolderIndex]))
                         {
                         {
-                            Pic(Pics.IndexOf(x));
+                            await Pic(Pics.IndexOf(x)).ConfigureAwait(false);
                         }
                         }
                         else
                         else
                         {
                         {
-                            Pic(x);
+                            await Pic(x).ConfigureAwait(false);
                         }
                         }
                     }
                     }
                     else
                     else
                     {
                     {
-                        Pic(x);
+                        await Pic(x).ConfigureAwait(false);
                     }
                     }
 
 
                     if (files.Length > 1)
                     if (files.Length > 1)
@@ -151,7 +152,7 @@ namespace PicView.FileHandling
 
 
             if (Base64.IsBase64String(s))
             if (Base64.IsBase64String(s))
             {
             {
-                Pic64(s);
+                await Pic64(s).ConfigureAwait(false);
                 return;
                 return;
             }
             }
 
 
@@ -165,7 +166,7 @@ namespace PicView.FileHandling
 
 
             if (File.Exists(s))
             if (File.Exists(s))
             {
             {
-                Pic(s);
+                await Pic(s).ConfigureAwait(false);
             }
             }
             else if (Directory.Exists(s))
             else if (Directory.Exists(s))
             {
             {
@@ -173,7 +174,7 @@ namespace PicView.FileHandling
                 Pics = FileList(s);
                 Pics = FileList(s);
                 if (Pics.Count > 0)
                 if (Pics.Count > 0)
                 {
                 {
-                    Pic(Pics[0]);
+                    await Pic(Pics[0]).ConfigureAwait(false);
                 }
                 }
                 else if (Pics.Count == 0)
                 else if (Pics.Count == 0)
                 {
                 {
@@ -181,7 +182,7 @@ namespace PicView.FileHandling
                 }
                 }
                 else if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]))
                 else if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]))
                 {
                 {
-                    Pic(Pics[FolderIndex]);
+                    await Pic(Pics[FolderIndex]).ConfigureAwait(false);
                 }
                 }
                 else
                 else
                 {
                 {
@@ -190,7 +191,7 @@ namespace PicView.FileHandling
             }
             }
             else if (Uri.IsWellFormedUriString(s, UriKind.Absolute)) // Check if from web
             else if (Uri.IsWellFormedUriString(s, UriKind.Absolute)) // Check if from web
             {
             {
-                LoadFromWeb.PicWeb(s);
+                await LoadFromWeb.PicWeb(s).ConfigureAwait(false);
             }
             }
             else
             else
             {
             {

+ 5 - 4
PicView/FileHandling/Open_Save.cs

@@ -3,6 +3,7 @@ using PicView.ImageHandling;
 using System;
 using System;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.IO;
 using System.IO;
+using System.Threading.Tasks;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 using static PicView.ChangeImage.Error_Handling;
 using static PicView.ChangeImage.Error_Handling;
 using static PicView.ChangeImage.Navigation;
 using static PicView.ChangeImage.Navigation;
@@ -52,7 +53,7 @@ namespace PicView.FileHandling
         /// <summary>
         /// <summary>
         /// Open a file dialog where user can select a supported file
         /// Open a file dialog where user can select a supported file
         /// </summary>
         /// </summary>
-        internal static void Open()
+        internal static async Task Open()
         {
         {
             IsDialogOpen = true;
             IsDialogOpen = true;
 
 
@@ -63,7 +64,7 @@ namespace PicView.FileHandling
             };
             };
             if (dlg.ShowDialog().Value)
             if (dlg.ShowDialog().Value)
             {
             {
-                Pic(dlg.FileName);
+                await Pic(dlg.FileName).ConfigureAwait(false);
             }
             }
             else
             else
             {
             {
@@ -102,7 +103,7 @@ namespace PicView.FileHandling
         /// <summary>
         /// <summary>
         /// Open a File Dialog, where the user can save a supported file type.
         /// Open a File Dialog, where the user can save a supported file type.
         /// </summary>
         /// </summary>
-        internal static void SaveFiles()
+        internal static async Task SaveFiles()
         {
         {
             string fileName;
             string fileName;
 
 
@@ -145,7 +146,7 @@ namespace PicView.FileHandling
             if (Savedlg.FileName == fileName)
             if (Savedlg.FileName == fileName)
             {
             {
                 //Refresh the list of pictures.
                 //Refresh the list of pictures.
-                Reload();
+                await Reload().ConfigureAwait(false);
             }
             }
 
 
             Close_UserControls();
             Close_UserControls();

+ 3 - 3
PicView/FileHandling/RecentFiles.cs

@@ -19,7 +19,7 @@ namespace PicView.FileHandling
         /// <summary>
         /// <summary>
         /// File list for Most Recently Used files
         /// File list for Most Recently Used files
         /// </summary>
         /// </summary>
-        internal static Queue<string> MRUlist;
+        private static Queue<string> MRUlist;
 
 
         /// <summary>
         /// <summary>
         /// How many max recent files
         /// How many max recent files
@@ -126,7 +126,7 @@ namespace PicView.FileHandling
         /// Adds events and submenu items to recent items in the context menu
         /// Adds events and submenu items to recent items in the context menu
         /// </summary>
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="sender"></param>
-        internal static void Recentcm_MouseEnter(object sender)
+        internal static void Recentcm_Opened(object sender)
         {
         {
             // Need to register the object as a MenuItem to use it
             // Need to register the object as a MenuItem to use it
             var RecentFilesMenuItem = (MenuItem)sender;
             var RecentFilesMenuItem = (MenuItem)sender;
@@ -193,7 +193,7 @@ namespace PicView.FileHandling
                     ToolTip = item
                     ToolTip = item
                 };
                 };
                 // Set tooltip as argument to avoid subscribing and unsubscribing to events
                 // Set tooltip as argument to avoid subscribing and unsubscribing to events
-                menuItem.Click += (x, xx) => Pic(menuItem.ToolTip.ToString());
+                menuItem.Click += async (x, xx) => await Pic(menuItem.ToolTip.ToString()).ConfigureAwait(false);
                 menuItem.Icon = cmIcon;
                 menuItem.Icon = cmIcon;
                 var ext = Path.GetExtension(item);
                 var ext = Path.GetExtension(item);
                 var ext5 = !string.IsNullOrWhiteSpace(ext) && ext.Length >= 5 ? ext.Substring(0, 5) : ext;
                 var ext5 = !string.IsNullOrWhiteSpace(ext) && ext.Length >= 5 ? ext.Substring(0, 5) : ext;

+ 48 - 0
PicView/ImageHandling/DisplayUnsupportedImage.cs

@@ -0,0 +1,48 @@
+using PicView.UI.Animations;
+using SkiaSharp;
+using SkiaSharp.Views.WPF;
+using System.Windows.Media.Imaging;
+
+namespace PicView.ImageHandling
+{
+    internal static class DisplayUnsupportedImage
+    {
+        internal static WriteableBitmap DrawUnsupportedImageText()
+        {
+            var info = new SKImageInfo(1024, 1024);
+            using var surface = SKSurface.Create(info);
+            SKCanvas canvas = surface.Canvas;
+
+            using var sKBitmap = new SKBitmap(info);
+
+            canvas.Clear(SKColors.White);
+
+            var color = AnimationHelper.GetPrefferedColorDown();
+
+            // draw centered text, stroked
+            using var paint = new SKPaint
+            {
+                TextSize = 64.0f,
+                IsAntialias = true,
+                Color = new SKColor(color.R, color.G, color.B),
+                TextAlign = SKTextAlign.Center,
+            };
+
+            float x = (info.Width - sKBitmap.Width) / 2;
+            float y = (info.Height - sKBitmap.Height) / 2;
+
+            canvas.DrawText("Unable to render image", 500, 100, paint);
+
+            canvas.Flush();
+
+            canvas.DrawBitmap(sKBitmap, x, y);
+
+            canvas.Dispose();
+
+            var writeableBitmap = sKBitmap.ToWriteableBitmap();
+            writeableBitmap.Freeze();
+            return writeableBitmap;
+
+        }
+    }
+}

+ 11 - 4
PicView/ImageHandling/Thumbnails.cs

@@ -48,12 +48,19 @@ namespace PicView.ImageHandling
         {
         {
             BitmapSource pic;
             BitmapSource pic;
 
 
-            if (picGallery.Container.Children.Count > 0)
+            if (picGallery != null)
             {
             {
-                if (x < picGallery.Container.Children.Count && picGallery.Container.Children.Count == Pics.Count)
+                if (picGallery.Container.Children.Count > 0)
                 {
                 {
-                    var y = picGallery.Container.Children[x] as PicGalleryItem;
-                    pic = (BitmapSource)y.img.Source;
+                    if (x < picGallery.Container.Children.Count && picGallery.Container.Children.Count == Pics.Count)
+                    {
+                        var y = picGallery.Container.Children[x] as PicGalleryItem;
+                        pic = (BitmapSource)y.img.Source;
+                    }
+                    else
+                    {
+                        pic = GetBitmapSourceThumb(Pics[x]);
+                    }
                 }
                 }
                 else
                 else
                 {
                 {

+ 1 - 1
PicView/Shortcuts/GotoPicsShortcuts.cs

@@ -54,7 +54,7 @@ namespace PicView
                     break;
                     break;
 
 
                 case Key.Enter: // Execute it!
                 case Key.Enter: // Execute it!
-                    GoToPicEvent(sender, e);
+                    GoToPicEventAsync(sender, e);
                     ClearGoTo();
                     ClearGoTo();
                     break;
                     break;
 
 

+ 1 - 1
PicView/SystemIntegration/NativeMethods.cs

@@ -102,7 +102,7 @@ namespace PicView.SystemIntegration
         private const int WM_SIZING = 0x214;
         private const int WM_SIZING = 0x214;
 
 
         private const int WM_EXITSIZEMOVE = 0x232;
         private const int WM_EXITSIZEMOVE = 0x232;
-        private static bool WindowWasResized = false;
+        private static bool WindowWasResized;
 
 
         public static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
         public static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
         {
         {

+ 2 - 1
PicView/SystemIntegration/Wallpaper.cs

@@ -63,8 +63,9 @@ namespace PicView.SystemIntegration
                         File.Delete(tempPath + randomName);
                         File.Delete(tempPath + randomName);
                         using var timer = new Timer(2000);
                         using var timer = new Timer(2000);
                         timer.Elapsed += (s, x) => Directory.Delete(tempPath);
                         timer.Elapsed += (s, x) => Directory.Delete(tempPath);
-                        return;
                     });
                     });
+
+                    return;
                 }
                 }
                 // TODO add Base64 support
                 // TODO add Base64 support
                 //if (Base64.IsBase64String(s))
                 //if (Base64.IsBase64String(s))

+ 20 - 4
PicView/UI/Animations/AnimationHelper.cs

@@ -16,24 +16,40 @@ namespace PicView.UI.Animations
 
 
         internal static void Fade(UIElement element, double to, Duration duration)
         internal static void Fade(UIElement element, double to, Duration duration)
         {
         {
-            var da = new DoubleAnimation()
+            var da = new DoubleAnimation
             {
             {
                 To = to,
                 To = to,
                 Duration = duration
                 Duration = duration
             };
             };
-            element.BeginAnimation(UIElement.OpacityProperty, da);
+
+            try
+            {
+                element.BeginAnimation(UIElement.OpacityProperty, da);
+            }
+            catch (Exception)
+            {
+                return;
+            }
         }
         }
 
 
         internal static void Fade(UIElement element, Duration duration, TimeSpan begintime, double from, double to)
         internal static void Fade(UIElement element, Duration duration, TimeSpan begintime, double from, double to)
         {
         {
-            var da = new DoubleAnimation()
+            var da = new DoubleAnimation
             {
             {
                 From = from,
                 From = from,
                 To = to,
                 To = to,
                 BeginTime = begintime,
                 BeginTime = begintime,
                 Duration = duration
                 Duration = duration
             };
             };
-            element.BeginAnimation(UIElement.OpacityProperty, da);
+
+            try
+            {
+                element.BeginAnimation(UIElement.OpacityProperty, da);
+            }
+            catch (Exception)
+            {
+                return;
+            }
         }
         }
 
 
         #endregion Fade
         #endregion Fade

+ 2 - 1
PicView/UI/Animations/FadeControls.cs

@@ -1,5 +1,6 @@
 using PicView.Library;
 using PicView.Library;
 using System;
 using System;
+using System.Threading.Tasks;
 using static PicView.Library.Fields;
 using static PicView.Library.Fields;
 using static PicView.UI.UserControls.UC;
 using static PicView.UI.UserControls.UC;
 
 
@@ -11,7 +12,7 @@ namespace PicView.UI.Animations
         /// Hides/shows interface elements with a fade animation
         /// Hides/shows interface elements with a fade animation
         /// </summary>
         /// </summary>
         /// <param name="show"></param>
         /// <param name="show"></param>
-        internal static async void FadeControlsAsync(bool show, double time = .5)
+        internal static async Task FadeControlsAsync(bool show, double time = .5)
         {
         {
             await mainWindow.Dispatcher.BeginInvoke((Action)(() =>
             await mainWindow.Dispatcher.BeginInvoke((Action)(() =>
             {
             {

+ 5 - 5
PicView/UI/DragAndDrop.cs

@@ -128,7 +128,7 @@ namespace PicView.UI
         /// </summary>
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="sender"></param>
         /// <param name="e"></param>
         /// <param name="e"></param>
-        internal static void Image_Drop(object sender, DragEventArgs e)
+        internal static async Task Image_Drop(object sender, DragEventArgs e)
         {
         {
             if (e.Data.GetData(DataFormats.Html) != null)
             if (e.Data.GetData(DataFormats.Html) != null)
             {
             {
@@ -138,7 +138,7 @@ namespace PicView.UI
                     string dataStr = Encoding.Unicode.GetString(data.ToArray());
                     string dataStr = Encoding.Unicode.GetString(data.ToArray());
                     string[] parts = dataStr.Split((char)10);
                     string[] parts = dataStr.Split((char)10);
 
 
-                    Pic(parts[0]);
+                    await Pic(parts[0]).ConfigureAwait(false);
                     return;
                     return;
                 }
                 }
             }
             }
@@ -151,13 +151,13 @@ namespace PicView.UI
             {
             {
                 if (Path.GetExtension(files[0]) == ".url")
                 if (Path.GetExtension(files[0]) == ".url")
                 {
                 {
-                    Pic(files[0]);
+                    await Pic(files[0]).ConfigureAwait(false);
                 }
                 }
                 else if (Directory.Exists(files[0]))
                 else if (Directory.Exists(files[0]))
                 {
                 {
                     if (Directory.GetFiles(files[0]).Length > 0)
                     if (Directory.GetFiles(files[0]).Length > 0)
                     {
                     {
-                        PicFolder(files[0]);
+                        PicFolderAsync(files[0]);
                     }
                     }
                     return;
                     return;
                 }
                 }
@@ -174,7 +174,7 @@ namespace PicView.UI
             }
             }
 
 
             // Load it
             // Load it
-            Pic(files[0]);
+            await Pic(files[0]).ConfigureAwait(false);
 
 
             // Don't show drop message any longer
             // Don't show drop message any longer
             CloseToolTipMessage();
             CloseToolTipMessage();

+ 11 - 12
PicView/UI/Loading/EventsHandling.cs

@@ -12,7 +12,6 @@ using static PicView.FileHandling.Copy_Paste;
 using static PicView.FileHandling.DeleteFiles;
 using static PicView.FileHandling.DeleteFiles;
 using static PicView.FileHandling.Open_Save;
 using static PicView.FileHandling.Open_Save;
 using static PicView.Library.Fields;
 using static PicView.Library.Fields;
-using static PicView.Library.Utilities;
 using static PicView.Shortcuts.MainShortcuts;
 using static PicView.Shortcuts.MainShortcuts;
 using static PicView.UI.Animations.MouseOverAnimations;
 using static PicView.UI.Animations.MouseOverAnimations;
 using static PicView.UI.DragAndDrop;
 using static PicView.UI.DragAndDrop;
@@ -54,17 +53,17 @@ namespace PicView.UI.Loading
             mainWindow.FileMenuButton.MouseLeave += (s, x) => AnimationHelper.MouseLeaveBgColor(mainWindow.FileMenuBg);
             mainWindow.FileMenuButton.MouseLeave += (s, x) => AnimationHelper.MouseLeaveBgColor(mainWindow.FileMenuBg);
             mainWindow.FileMenuButton.Click += Toggle_open_menu;
             mainWindow.FileMenuButton.Click += Toggle_open_menu;
 
 
-            fileMenu.Open.Click += (s, x) => Open();
+            fileMenu.Open.Click += (s, x) => Open().ConfigureAwait(false);
             fileMenu.FileLocation.Click += (s, x) => Open_In_Explorer();
             fileMenu.FileLocation.Click += (s, x) => Open_In_Explorer();
             fileMenu.Print.Click += (s, x) => Print(Pics[FolderIndex]);
             fileMenu.Print.Click += (s, x) => Print(Pics[FolderIndex]);
-            fileMenu.SaveBorder.Click += (s, x) => SaveFiles();
+            fileMenu.SaveBorder.Click += async (s, x) => await SaveFiles().ConfigureAwait(false); ;
 
 
-            fileMenu.OpenBorder.MouseLeftButtonUp += (s, x) => Open();
+            fileMenu.OpenBorder.MouseLeftButtonUp += async (s, x) => await Open().ConfigureAwait(false); ;
             fileMenu.FileLocationBorder.MouseLeftButtonUp += (s, x) => Open_In_Explorer();
             fileMenu.FileLocationBorder.MouseLeftButtonUp += (s, x) => Open_In_Explorer();
             fileMenu.PrintBorder.MouseLeftButtonUp += (s, x) => Print(Pics[FolderIndex]);
             fileMenu.PrintBorder.MouseLeftButtonUp += (s, x) => Print(Pics[FolderIndex]);
-            fileMenu.Save_File_Location_Border.MouseLeftButtonUp += (s, x) => SaveFiles();
+            fileMenu.Save_File_Location_Border.MouseLeftButtonUp += async (s, x) => await SaveFiles().ConfigureAwait(false); ;
 
 
-            fileMenu.PasteButton.Click += (s, x) => Paste();
+            fileMenu.PasteButton.Click += async (s, x) => await Paste();
             fileMenu.CopyButton.Click += (s, x) => Copyfile();
             fileMenu.CopyButton.Click += (s, x) => Copyfile();
 
 
             // image_button
             // image_button
@@ -97,7 +96,7 @@ namespace PicView.UI.Loading
             mainWindow.LeftButton.MouseEnter += (s, x) => AnimationHelper.MouseEnterBgTexColor(mainWindow.LeftButtonBrush);
             mainWindow.LeftButton.MouseEnter += (s, x) => AnimationHelper.MouseEnterBgTexColor(mainWindow.LeftButtonBrush);
             mainWindow.LeftButton.MouseLeave += (s, x) => ButtonMouseLeaveAnim(mainWindow.LeftArrowFill);
             mainWindow.LeftButton.MouseLeave += (s, x) => ButtonMouseLeaveAnim(mainWindow.LeftArrowFill);
             mainWindow.LeftButton.MouseLeave += (s, x) => AnimationHelper.MouseLeaveBgTexColor(mainWindow.LeftButtonBrush);
             mainWindow.LeftButton.MouseLeave += (s, x) => AnimationHelper.MouseLeaveBgTexColor(mainWindow.LeftButtonBrush);
-            mainWindow.LeftButton.Click += (s, x) => PicButton(false, false);
+            mainWindow.LeftButton.Click += async (s, x) => await PicButton(false, false).ConfigureAwait(false);
 
 
             // RightButton
             // RightButton
             mainWindow.RightButton.PreviewMouseLeftButtonDown += (s, x) => PreviewMouseButtonDownAnim(mainWindow.RightArrowFill);
             mainWindow.RightButton.PreviewMouseLeftButtonDown += (s, x) => PreviewMouseButtonDownAnim(mainWindow.RightArrowFill);
@@ -105,7 +104,7 @@ namespace PicView.UI.Loading
             mainWindow.RightButton.MouseEnter += (s, x) => AnimationHelper.MouseEnterBgTexColor(mainWindow.RightButtonBrush);
             mainWindow.RightButton.MouseEnter += (s, x) => AnimationHelper.MouseEnterBgTexColor(mainWindow.RightButtonBrush);
             mainWindow.RightButton.MouseLeave += (s, x) => ButtonMouseLeaveAnim(mainWindow.RightArrowFill);
             mainWindow.RightButton.MouseLeave += (s, x) => ButtonMouseLeaveAnim(mainWindow.RightArrowFill);
             mainWindow.RightButton.MouseLeave += (s, x) => AnimationHelper.MouseLeaveBgTexColor(mainWindow.RightButtonBrush);
             mainWindow.RightButton.MouseLeave += (s, x) => AnimationHelper.MouseLeaveBgTexColor(mainWindow.RightButtonBrush);
-            mainWindow.RightButton.Click += (s, x) => PicButton(false, true);
+            mainWindow.RightButton.Click += async (s, x) => await PicButton(false, true).ConfigureAwait(false);
 
 
             // SettingsButton
             // SettingsButton
             mainWindow.SettingsButton.PreviewMouseLeftButtonDown += (s, x) => PreviewMouseButtonDownAnim(mainWindow.SettingsButtonFill);
             mainWindow.SettingsButton.PreviewMouseLeftButtonDown += (s, x) => PreviewMouseButtonDownAnim(mainWindow.SettingsButtonFill);
@@ -128,10 +127,10 @@ namespace PicView.UI.Loading
             imageSettingsMenu.FlipButton.Click += (s, x) => Flip();
             imageSettingsMenu.FlipButton.Click += (s, x) => Flip();
 
 
             // ClickArrows
             // ClickArrows
-            clickArrowLeft.MouseLeftButtonDown += (s, x) => PicButton(true, false);
+            clickArrowLeft.MouseLeftButtonDown += async (s, x) => await PicButton(true, false).ConfigureAwait(false);
             clickArrowLeft.MouseEnter += Interface_MouseEnter_Negative;
             clickArrowLeft.MouseEnter += Interface_MouseEnter_Negative;
 
 
-            clickArrowRight.MouseLeftButtonDown += (s, x) => PicButton(true, true);
+            clickArrowRight.MouseLeftButtonDown += async (s, x) => await PicButton(true, true).ConfigureAwait(false);
             clickArrowRight.MouseEnter += Interface_MouseEnter_Negative;
             clickArrowRight.MouseEnter += Interface_MouseEnter_Negative;
 
 
             // x2
             // x2
@@ -160,7 +159,7 @@ namespace PicView.UI.Loading
 
 
             // bg
             // bg
             mainWindow.bg.MouseLeftButtonDown += Bg_MouseLeftButtonDown;
             mainWindow.bg.MouseLeftButtonDown += Bg_MouseLeftButtonDown;
-            mainWindow.bg.Drop += Image_Drop;
+            mainWindow.bg.Drop += async (s, x) => await Image_Drop(s, x).ConfigureAwait(false);
             mainWindow.bg.DragEnter += Image_DragEnter;
             mainWindow.bg.DragEnter += Image_DragEnter;
             mainWindow.bg.DragLeave += Image_DragLeave;
             mainWindow.bg.DragLeave += Image_DragLeave;
             mainWindow.bg.MouseEnter += Interface_MouseEnter;
             mainWindow.bg.MouseEnter += Interface_MouseEnter;
@@ -180,7 +179,7 @@ namespace PicView.UI.Loading
             //Logobg.PreviewMouseLeftButtonDown += LogoMouseButtonDown;
             //Logobg.PreviewMouseLeftButtonDown += LogoMouseButtonDown;
 
 
             // Lower Bar
             // Lower Bar
-            mainWindow.LowerBar.Drop += Image_Drop;
+            mainWindow.LowerBar.Drop += async (s, x) => await Image_Drop(s, x).ConfigureAwait(false);
             mainWindow.LowerBar.MouseLeftButtonDown += Move;
             mainWindow.LowerBar.MouseLeftButtonDown += Move;
 
 
             // This
             // This

+ 15 - 15
PicView/UI/Loading/LoadContextMenus.cs

@@ -158,8 +158,8 @@ namespace PicView.UI.Loading
                 MinWidth = 125,
                 MinWidth = 125,
                 IsChecked = Properties.Settings.Default.SortPreference == 0
                 IsChecked = Properties.Settings.Default.SortPreference == 0
             };
             };
-            sortcmChild0Header.Click += delegate { UpdateUIValues.ChangeSorting(0); cm.IsOpen = false; };
-            sortcmChild0.Click += delegate { UpdateUIValues.ChangeSorting(0); cm.IsOpen = false; };
+            sortcmChild0Header.Click += delegate { UpdateUIValues.ChangeSortingAsync(0); cm.IsOpen = false; };
+            sortcmChild0.Click += delegate { UpdateUIValues.ChangeSortingAsync(0); cm.IsOpen = false; };
             sortcmChild0.Header = sortcmChild0Header;
             sortcmChild0.Header = sortcmChild0Header;
             sortcm.Items.Add(sortcmChild0);
             sortcm.Items.Add(sortcmChild0);
 
 
@@ -174,8 +174,8 @@ namespace PicView.UI.Loading
                 MinWidth = 125,
                 MinWidth = 125,
                 IsChecked = Properties.Settings.Default.SortPreference == 1
                 IsChecked = Properties.Settings.Default.SortPreference == 1
             };
             };
-            sortcmChild1Header.Click += delegate { UpdateUIValues.ChangeSorting(1); cm.IsOpen = false; };
-            sortcmChild1.Click += delegate { UpdateUIValues.ChangeSorting(1); cm.IsOpen = false; };
+            sortcmChild1Header.Click += delegate { UpdateUIValues.ChangeSortingAsync(1); cm.IsOpen = false; };
+            sortcmChild1.Click += delegate { UpdateUIValues.ChangeSortingAsync(1); cm.IsOpen = false; };
             sortcmChild1.Header = sortcmChild1Header;
             sortcmChild1.Header = sortcmChild1Header;
             sortcm.Items.Add(sortcmChild1);
             sortcm.Items.Add(sortcmChild1);
 
 
@@ -190,8 +190,8 @@ namespace PicView.UI.Loading
                 MinWidth = 125,
                 MinWidth = 125,
                 IsChecked = Properties.Settings.Default.SortPreference == 2
                 IsChecked = Properties.Settings.Default.SortPreference == 2
             };
             };
-            sortcmChild2Header.Click += delegate { UpdateUIValues.ChangeSorting(2); cm.IsOpen = false; };
-            sortcmChild2.Click += delegate { UpdateUIValues.ChangeSorting(2); cm.IsOpen = false; };
+            sortcmChild2Header.Click += delegate { UpdateUIValues.ChangeSortingAsync(2); cm.IsOpen = false; };
+            sortcmChild2.Click += delegate { UpdateUIValues.ChangeSortingAsync(2); cm.IsOpen = false; };
             sortcmChild2.Header = sortcmChild2Header;
             sortcmChild2.Header = sortcmChild2Header;
             sortcm.Items.Add(sortcmChild2);
             sortcm.Items.Add(sortcmChild2);
 
 
@@ -206,8 +206,8 @@ namespace PicView.UI.Loading
                 MinWidth = 125,
                 MinWidth = 125,
                 IsChecked = Properties.Settings.Default.SortPreference == 3
                 IsChecked = Properties.Settings.Default.SortPreference == 3
             };
             };
-            sortcmChild3Header.Click += delegate { UpdateUIValues.ChangeSorting(3); cm.IsOpen = false; };
-            sortcmChild3.Click += delegate { UpdateUIValues.ChangeSorting(3); cm.IsOpen = false; };
+            sortcmChild3Header.Click += delegate { UpdateUIValues.ChangeSortingAsync(3); cm.IsOpen = false; };
+            sortcmChild3.Click += delegate { UpdateUIValues.ChangeSortingAsync(3); cm.IsOpen = false; };
             sortcmChild3.Header = sortcmChild3Header;
             sortcmChild3.Header = sortcmChild3Header;
             sortcm.Items.Add(sortcmChild3);
             sortcm.Items.Add(sortcmChild3);
 
 
@@ -222,8 +222,8 @@ namespace PicView.UI.Loading
                 MinWidth = 125,
                 MinWidth = 125,
                 IsChecked = Properties.Settings.Default.SortPreference == 4
                 IsChecked = Properties.Settings.Default.SortPreference == 4
             };
             };
-            sortcmChild4Header.Click += delegate { UpdateUIValues.ChangeSorting(4); cm.IsOpen = false; };
-            sortcmChild4.Click += delegate { UpdateUIValues.ChangeSorting(4); cm.IsOpen = false; };
+            sortcmChild4Header.Click += delegate { UpdateUIValues.ChangeSortingAsync(4); cm.IsOpen = false; };
+            sortcmChild4.Click += delegate { UpdateUIValues.ChangeSortingAsync(4); cm.IsOpen = false; };
             sortcmChild4.Header = sortcmChild4Header;
             sortcmChild4.Header = sortcmChild4Header;
             sortcm.Items.Add(sortcmChild4);
             sortcm.Items.Add(sortcmChild4);
 
 
@@ -238,8 +238,8 @@ namespace PicView.UI.Loading
                 MinWidth = 125,
                 MinWidth = 125,
                 IsChecked = Properties.Settings.Default.SortPreference == 5
                 IsChecked = Properties.Settings.Default.SortPreference == 5
             };
             };
-            sortcmChild5Header.Click += delegate { UpdateUIValues.ChangeSorting(5); cm.IsOpen = false; };
-            sortcmChild5.Click += delegate { UpdateUIValues.ChangeSorting(5); cm.IsOpen = false; };
+            sortcmChild5Header.Click += delegate { UpdateUIValues.ChangeSortingAsync(5); cm.IsOpen = false; };
+            sortcmChild5.Click += delegate { UpdateUIValues.ChangeSortingAsync(5); cm.IsOpen = false; };
             sortcmChild5.Header = sortcmChild5Header;
             sortcmChild5.Header = sortcmChild5Header;
             sortcm.Items.Add(sortcmChild5);
             sortcm.Items.Add(sortcmChild5);
 
 
@@ -254,8 +254,8 @@ namespace PicView.UI.Loading
                 MinWidth = 125,
                 MinWidth = 125,
                 IsChecked = Properties.Settings.Default.SortPreference == 6
                 IsChecked = Properties.Settings.Default.SortPreference == 6
             };
             };
-            sortcmChild6Header.Click += delegate { UpdateUIValues.ChangeSorting(6); cm.IsOpen = false; };
-            sortcmChild6.Click += delegate { UpdateUIValues.ChangeSorting(6); cm.IsOpen = false; };
+            sortcmChild6Header.Click += delegate { UpdateUIValues.ChangeSortingAsync(6); cm.IsOpen = false; };
+            sortcmChild6.Click += delegate { UpdateUIValues.ChangeSortingAsync(6); cm.IsOpen = false; };
             sortcmChild6.Header = sortcmChild6Header;
             sortcmChild6.Header = sortcmChild6Header;
             sortcm.Items.Add(sortcmChild6);
             sortcm.Items.Add(sortcmChild6);
             cm.Items.Add(sortcm);
             cm.Items.Add(sortcm);
@@ -724,7 +724,7 @@ namespace PicView.UI.Loading
                     break;
                     break;
             }
             }
 
 
-            cm.Opened += (tt, yy) => Recentcm_MouseEnter(recentcm);
+            cm.Opened += (tt, yy) => Recentcm_Opened(recentcm);
 
 
 #if DEBUG
 #if DEBUG
             Trace.WriteLine("Contextmenu loaded");
             Trace.WriteLine("Contextmenu loaded");

+ 17 - 8
PicView/UI/Loading/StartLoading.cs

@@ -5,6 +5,7 @@ using PicView.UI.UserControls;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;
+using System.Globalization;
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
 using System.Windows.Interop;
 using System.Windows.Interop;
@@ -54,7 +55,7 @@ namespace PicView.UI.Loading
             AjaxLoadingStart();
             AjaxLoadingStart();
         }
         }
 
 
-        internal static void Start()
+        internal static async void Start()
         {
         {
 #if DEBUG
 #if DEBUG
             Trace.WriteLine("ContentRendered started");
             Trace.WriteLine("ContentRendered started");
@@ -98,8 +99,6 @@ namespace PicView.UI.Loading
             }
             }
             else
             else
             {
             {
-                Pic(Application.Current.Properties["ArbitraryArgName"].ToString());
-
                 if (Properties.Settings.Default.Fullscreen)
                 if (Properties.Settings.Default.Fullscreen)
                 {
                 {
                     Fullscreen_Restore(true);
                     Fullscreen_Restore(true);
@@ -112,8 +111,22 @@ namespace PicView.UI.Loading
                 {
                 {
                     ConfigColors.UpdateColor();
                     ConfigColors.UpdateColor();
                 }
                 }
+
+                await Pic(Application.Current.Properties["ArbitraryArgName"].ToString()).ConfigureAwait(false);
             }
             }
 
 
+            await mainWindow.Dispatcher.BeginInvoke((Action)(() =>
+            {
+                AddUIElementsAndUpdateValues();
+            }));
+
+#if DEBUG
+            Trace.WriteLine("Start Completed ");
+#endif
+        }
+
+        private static void AddUIElementsAndUpdateValues()
+        {
             // Update values
             // Update values
             ConfigColors.SetColors();
             ConfigColors.SetColors();
             mainWindow.AllowDrop = true;
             mainWindow.AllowDrop = true;
@@ -175,6 +188,7 @@ namespace PicView.UI.Loading
 
 
             // Add things!
             // Add things!
             Eventshandling.Go();
             Eventshandling.Go();
+            AjaxLoadingEnd();
             AddTimers();
             AddTimers();
             AddContextMenus();
             AddContextMenus();
 
 
@@ -184,11 +198,6 @@ namespace PicView.UI.Loading
                 Properties.Settings.Default.Upgrade();
                 Properties.Settings.Default.Upgrade();
                 Properties.Settings.Default.CallUpgrade = false;
                 Properties.Settings.Default.CallUpgrade = false;
             }
             }
-            AjaxLoadingEnd();
-
-#if DEBUG
-            Trace.WriteLine("Start Completed ");
-#endif
         }
         }
     }
     }
 }
 }

+ 13 - 8
PicView/UI/PicGallery/GalleryClick.cs

@@ -1,5 +1,6 @@
 using PicView.ChangeImage;
 using PicView.ChangeImage;
 using System;
 using System;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
 using System.Windows.Media;
 using System.Windows.Media;
@@ -16,7 +17,7 @@ namespace PicView.UI.PicGallery
 {
 {
     internal static class GalleryClick
     internal static class GalleryClick
     {
     {
-        internal static void Click(int id)
+        internal static async Task ClickAsync(int id)
         {
         {
             mainWindow.Focus();
             mainWindow.Focus();
 
 
@@ -75,12 +76,16 @@ namespace PicView.UI.PicGallery
                     DecelerationRatio = deceleration
                     DecelerationRatio = deceleration
                 };
                 };
 
 
-                da.Completed += delegate
+                da.Completed += async delegate
                 {
                 {
-                    ItemClick(id);
-                    picGallery.grid.Children.Remove(border);
+                    await ItemClickAsync(id).ConfigureAwait(false);
+                    await mainWindow.Dispatcher.BeginInvoke((Action)(() =>
+                    {
+                        picGallery.grid.Children.Remove(border);
+                        img = null;
+                    }));
                     IsOpen = false;
                     IsOpen = false;
-                    img = null;
+                    
                 };
                 };
 
 
                 border.BeginAnimation(FrameworkElement.WidthProperty, da);
                 border.BeginAnimation(FrameworkElement.WidthProperty, da);
@@ -89,7 +94,7 @@ namespace PicView.UI.PicGallery
             else
             else
             {
             {
                 Preloader.PreloaderFix(Pics[id]);
                 Preloader.PreloaderFix(Pics[id]);
-                ItemClick(id);
+                await ItemClickAsync(id).ConfigureAwait(false);
             }
             }
         }
         }
 
 
@@ -108,13 +113,13 @@ namespace PicView.UI.PicGallery
             }
             }
         }
         }
 
 
-        internal static void ItemClick(int id)
+        internal static async Task ItemClickAsync(int id)
         {
         {
             // Deselect current item
             // Deselect current item
             SetUnselected(FolderIndex);
             SetUnselected(FolderIndex);
 
 
             // Change image
             // Change image
-            Pic(id);
+            await Pic(id).ConfigureAwait(true);
 
 
             if (Properties.Settings.Default.PicGallery == 1)
             if (Properties.Settings.Default.PicGallery == 1)
             {
             {

+ 4 - 3
PicView/UI/PicGallery/GalleryFunctions.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.Diagnostics;
 using System.Diagnostics;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
@@ -27,15 +28,15 @@ namespace PicView.UI.PicGallery
             }
             }
         }
         }
 
 
-        internal static async void Add(BitmapSource pic, int id)
+        internal static async Task Add(BitmapSource pic, int id)
         {
         {
             await mainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
             await mainWindow.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
             {
             {
                 var selected = id == FolderIndex;
                 var selected = id == FolderIndex;
                 var item = new UserControls.PicGalleryItem(pic, id, selected);
                 var item = new UserControls.PicGalleryItem(pic, id, selected);
-                item.MouseLeftButtonUp += (s, x) =>
+                item.MouseLeftButtonDown += async delegate
                 {
                 {
-                    GalleryClick.Click(id);
+                    await GalleryClick.ClickAsync(id).ConfigureAwait(false);
                 };
                 };
                 picGallery.Container.Children.Add(item);
                 picGallery.Container.Children.Add(item);
             }));
             }));

+ 1 - 1
PicView/UI/PicGallery/GalleryToggle.cs

@@ -131,7 +131,7 @@ namespace PicView.UI.PicGallery
                 mainWindow.bg.Children.Remove(picGallery);
                 mainWindow.bg.Children.Remove(picGallery);
                 fakeWindow.grid.Children.Add(picGallery);
                 fakeWindow.grid.Children.Add(picGallery);
             }
             }
-            else if (!fakeWindow.grid.Children.Contains(picGallery))
+            else
             {
             {
                 mainWindow.bg.Children.Remove(picGallery);
                 mainWindow.bg.Children.Remove(picGallery);
                 fakeWindow.grid.Children.Add(picGallery);
                 fakeWindow.grid.Children.Add(picGallery);

+ 4 - 1
PicView/UI/Tooltip.cs

@@ -55,7 +55,10 @@ namespace PicView.UI
         /// </summary>
         /// </summary>
         internal static void CloseToolTipMessage()
         internal static void CloseToolTipMessage()
         {
         {
-            toolTipMessage.Visibility = Visibility.Hidden;
+            if (toolTipMessage.CheckAccess())
+            {
+                toolTipMessage.Visibility = Visibility.Hidden;
+            }
         }
         }
     }
     }
 }
 }

+ 6 - 0
PicView/UI/TransformImage/Zoom.cs

@@ -24,6 +24,12 @@ namespace PicView.UI.TransformImage
             get
             get
             {
             {
                 var zoom = Math.Round(AspectRatio * 100);
                 var zoom = Math.Round(AspectRatio * 100);
+
+                if (st == null)
+                {
+                    return string.Empty;
+                }
+
                 if (st.ScaleX == 1)
                 if (st.ScaleX == 1)
                 {
                 {
                     return string.Empty;
                     return string.Empty;

+ 3 - 2
PicView/UI/UpdateUIValues.cs

@@ -2,6 +2,7 @@
 using PicView.UI.Sizing;
 using PicView.UI.Sizing;
 using PicView.UI.UserControls;
 using PicView.UI.UserControls;
 using System.IO;
 using System.IO;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
 using static PicView.ChangeImage.Navigation;
 using static PicView.ChangeImage.Navigation;
@@ -14,7 +15,7 @@ namespace PicView.UI
 {
 {
     internal static class UpdateUIValues
     internal static class UpdateUIValues
     {
     {
-        internal static void ChangeSorting(short sorting)
+        internal static async Task ChangeSortingAsync(short sorting)
         {
         {
             if (Properties.Settings.Default.SortPreference == sorting)
             if (Properties.Settings.Default.SortPreference == sorting)
             {
             {
@@ -27,7 +28,7 @@ namespace PicView.UI
             {
             {
                 Pics = FileList(Path.GetDirectoryName(tmp));
                 Pics = FileList(Path.GetDirectoryName(tmp));
                 PreloadCount = 4;
                 PreloadCount = 4;
-                Pic(Pics.IndexOf(tmp));
+                await Pic(Pics.IndexOf(tmp)).ConfigureAwait(false);
             }
             }
             var sortcm = cm.Items[6] as MenuItem;
             var sortcm = cm.Items[6] as MenuItem;
 
 

+ 7 - 7
PicView/UI/UserControls/Buttons/ClickArrow.xaml.cs

@@ -9,12 +9,12 @@ namespace PicView.UI.UserControls
 {
 {
     public partial class ClickArrow : UserControl
     public partial class ClickArrow : UserControl
     {
     {
-        private static ColorAnimation ccAnim;
-        private static ColorAnimation ccAnim2;
-        private static Color bb;
-        private static Color bg;
-        private static Color bg2;
-        private static Color fg;
+        private ColorAnimation ccAnim;
+        private ColorAnimation ccAnim2;
+        private Color bb;
+        private Color bg;
+        private Color bg2;
+        private Color fg;
 
 
         public ClickArrow(bool right)
         public ClickArrow(bool right)
         {
         {
@@ -22,7 +22,7 @@ namespace PicView.UI.UserControls
 
 
             if (!right)
             if (!right)
             {
             {
-                Arrow.LayoutTransform = new ScaleTransform()
+                Arrow.LayoutTransform = new ScaleTransform
                 {
                 {
                     ScaleX = -1
                     ScaleX = -1
                 };
                 };

+ 6 - 6
PicView/UI/UserControls/Buttons/Minus.xaml.cs

@@ -12,12 +12,12 @@ namespace PicView.UI.UserControls
     /// </summary>
     /// </summary>
     public partial class Minus : UserControl
     public partial class Minus : UserControl
     {
     {
-        private static ColorAnimation ccAnim;
-        private static ColorAnimation ccAnim2;
-        private static Color bb;
-        private static Color bg;
-        private static Color bg2;
-        private static Color fg;
+        private ColorAnimation ccAnim;
+        private ColorAnimation ccAnim2;
+        private Color bb;
+        private Color bg;
+        private Color bg2;
+        private Color fg;
 
 
         public Minus()
         public Minus()
         {
         {

+ 1 - 1
PicView/UI/UserControls/Gallery/PicGallery.xaml.cs

@@ -11,7 +11,7 @@ namespace PicView.UI.UserControls
         public PicGallery()
         public PicGallery()
         {
         {
             InitializeComponent();
             InitializeComponent();
-            //PicGalleryLogic.IsLoading = PicGalleryLogic.IsOpen = false;
+
             Loaded += GalleryLoad.PicGallery_Loaded;
             Loaded += GalleryLoad.PicGallery_Loaded;
         }
         }
     }
     }

+ 1 - 1
PicView/UI/UserControls/Menus/QuickSettingsMenu.xaml

@@ -110,7 +110,7 @@
                                 Panel.ZIndex="1"
                                 Panel.ZIndex="1"
                                 AcceptsTab="False"
                                 AcceptsTab="False"
                                 IsTabStop="False"
                                 IsTabStop="False"
-                                Text="42"
+                                Text="1"
                                 TextAlignment="Center" />
                                 TextAlignment="Center" />
                         </Canvas>
                         </Canvas>
                     </Button.Content>
                     </Button.Content>

+ 1 - 1
PicView/UI/UserControls/Menus/QuickSettingsMenu.xaml.cs

@@ -47,7 +47,7 @@ namespace PicView.UI.UserControls
             SetFit.IsChecked = Properties.Settings.Default.AutoFitWindow;
             SetFit.IsChecked = Properties.Settings.Default.AutoFitWindow;
             SetFit.Click += UpdateUIValues.SetAutoFit;
             SetFit.Click += UpdateUIValues.SetAutoFit;
 
 
-            GoToPic.Click += GoToPicEvent;
+            GoToPic.Click += async (s, x) => await GoToPicEventAsync(s, x).ConfigureAwait(false);
             GoToPicBox.PreviewMouseLeftButtonDown += delegate
             GoToPicBox.PreviewMouseLeftButtonDown += delegate
             {
             {
                 GoToPicBox.CaretBrush = new SolidColorBrush(UI.ConfigColors.mainColor);
                 GoToPicBox.CaretBrush = new SolidColorBrush(UI.ConfigColors.mainColor);

+ 0 - 55
PicView/UI/UserControls/Misc/BadImage.xaml

@@ -1,55 +0,0 @@
-<UserControl
-    x:Class="PicView.UI.UserControls.BadImage"
-    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-    Width="465"
-    Height="500">
-    <Grid>
-        <Canvas
-            Width="463"
-            Height="457"
-            HorizontalAlignment="Center"
-            VerticalAlignment="Center">
-            <Path
-                x:Name="Top"
-                Canvas.Left="130"
-                Canvas.Top="242"
-                Data="M256 288c-45.443 0-83.675 26.076-102.205 64h204.41c-18.53-37.924-56.762-64-102.205-64z"
-                RenderTransformOrigin="0.5,0.5"
-                Stretch="Uniform">
-                <Path.Fill>
-                    <SolidColorBrush x:Name="TopFill" Color="{StaticResource MainColor}" />
-                </Path.Fill>
-            </Path>
-            <Path
-                x:Name="Head"
-                Canvas.Left="23"
-                Canvas.Top="10"
-                Data="M256 48C140.563 48 48 141.6 48 256s92.563 208 208 208 208-93.6 208-208S370.401 48 256 48zm0 374.4c-91.518 0-166.404-74.883-166.404-166.4 0-91.518 74.887-166.4 166.404-166.4S422.404 164.482 422.404 256 347.518 422.4 256 422.4z"
-                RenderTransformOrigin="0.5,0.5"
-                Stretch="Uniform">
-                <Path.Fill>
-                    <SolidColorBrush x:Name="HeadFill" Color="{StaticResource MainColor}" />
-                </Path.Fill>
-            </Path>
-            <Path
-                x:Name="Eyes"
-                Canvas.Left="126"
-                Canvas.Top="121"
-                Data="M328.8 235.2c17.683 0 31.201-13.518 31.201-31.2s-13.519-31.2-31.201-31.2c-17.682 0-31.2 13.518-31.2 31.2s13.518 31.2 31.2 31.2zM183.2 235.2c17.682 0 31.2-13.518 31.2-31.2s-13.519-31.2-31.2-31.2c-17.683 0-31.201 13.518-31.201 31.2s13.519 31.2 31.201 31.2z"
-                RenderTransformOrigin="0.5,0.5"
-                Stretch="Uniform">
-                <Path.Fill>
-                    <SolidColorBrush x:Name="EyesFill" Color="{StaticResource MainColor}" />
-                </Path.Fill>
-            </Path>
-        </Canvas>
-        <Label
-            Margin="0,452,0,0"
-            HorizontalAlignment="Center"
-            VerticalAlignment="Center"
-            FontSize="16">
-            The image could not be rendered
-        </Label>
-    </Grid>
-</UserControl>

+ 0 - 15
PicView/UI/UserControls/Misc/BadImage.xaml.cs

@@ -1,15 +0,0 @@
-using System.Windows.Controls;
-
-namespace PicView.UI.UserControls
-{
-    /// <summary>
-    /// Interaction logic for BadImage.xaml
-    /// </summary>
-    public partial class BadImage : UserControl
-    {
-        public BadImage()
-        {
-            InitializeComponent();
-        }
-    }
-}

+ 8 - 1
PicView/UI/UserControls/UC.cs

@@ -1,5 +1,6 @@
 using PicView.UI.Animations;
 using PicView.UI.Animations;
 using PicView.UI.PicGallery;
 using PicView.UI.PicGallery;
+using PicView.UI.Windows;
 using System;
 using System;
 using System.Windows;
 using System.Windows;
 using System.Windows.Media.Animation;
 using System.Windows.Media.Animation;
@@ -21,7 +22,6 @@ namespace PicView.UI.UserControls
         internal static Minus minus;
         internal static Minus minus;
         internal static PicGallery picGallery;
         internal static PicGallery picGallery;
         internal static GalleryShortcut galleryShortcut;
         internal static GalleryShortcut galleryShortcut;
-        internal static BadImage badImage;
         internal static CroppingTool cropppingTool;
         internal static CroppingTool cropppingTool;
 
 
         private static bool imageSettingsMenuOpen;
         private static bool imageSettingsMenuOpen;
@@ -112,6 +112,13 @@ namespace PicView.UI.UserControls
                 if (quickSettingsMenu != null)
                 if (quickSettingsMenu != null)
                 {
                 {
                     quickSettingsMenu.BeginAnimation(UIElement.OpacityProperty, da);
                     quickSettingsMenu.BeginAnimation(UIElement.OpacityProperty, da);
+                    if (Library.Fields.mainWindow.img.Source != null)
+                    {
+                        quickSettingsMenu.GoToPicBox.Text =
+                            (Library.Fields.FolderIndex + 1)
+                            .ToString(System.Globalization.CultureInfo.CurrentCulture);
+                    }
+
                 }
                 }
             }
             }
         }
         }