From 3cdf839f01114a99371a1ef0cdcfaf3bef6ca092 Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 13 Jun 2022 18:21:08 +0300 Subject: [PATCH] Get window icon async --- ShareX.HelpersLib/Native/NativeMethods_Helpers.cs | 4 +++- ShareX/Forms/MainForm.cs | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs index 600edc5fb..06c13f098 100644 --- a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs +++ b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs @@ -147,7 +147,9 @@ public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong) private static Icon GetSmallApplicationIcon(IntPtr handle) { - SendMessageTimeout(handle, (int)WindowsMessages.GETICON, NativeConstants.ICON_SMALL2, 0, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, out IntPtr iconHandle); + IntPtr iconHandle; + + SendMessageTimeout(handle, (int)WindowsMessages.GETICON, NativeConstants.ICON_SMALL2, 0, SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, out iconHandle); if (iconHandle == IntPtr.Zero) { diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs index 439d6f1c1..2be3def3c 100644 --- a/ShareX/Forms/MainForm.cs +++ b/ShareX/Forms/MainForm.cs @@ -1197,16 +1197,15 @@ private async Task PrepareCaptureMenuAsync(ToolStripMenuItem tsmiWindow, EventHa ToolStripMenuItem tsmi = new ToolStripMenuItem(title); tsmi.Tag = window; tsmi.Click += handlerWindow; + items.Add(tsmi); - using (Icon icon = window.Icon) + using (Icon icon = await Task.Run(() => window.Icon)) { if (icon != null && icon.Width > 0 && icon.Height > 0) { tsmi.Image = icon.ToBitmap(); } } - - items.Add(tsmi); } catch (Exception e) {