From 2f6587785290038d8c2dc5d2591be65775491901 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Tue, 4 Apr 2023 17:09:52 +0900 Subject: [PATCH 1/2] WarmUpQueryContextMenuAsync() --- src/Files.App/App.xaml.cs | 4 +++- src/Files.App/Shell/ContextMenu.cs | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 1eef42a97d81..0969650e5acf 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -13,6 +13,7 @@ using Files.App.ServicesImplementation; using Files.App.ServicesImplementation.DateTimeFormatter; using Files.App.ServicesImplementation.Settings; +using Files.App.Shell; using Files.App.Storage.NativeStorage; using Files.App.UserControls.MultitaskingControl; using Files.App.ViewModels; @@ -139,7 +140,8 @@ await Task.WhenAll( await Task.WhenAll( JumpListHelper.InitializeUpdatesAsync(), - addItemService.GetNewEntriesAsync() + addItemService.GetNewEntriesAsync(), + ContextMenu.WarmUpQueryContextMenuAsync() ); FileTagsHelper.UpdateTagsDb(); diff --git a/src/Files.App/Shell/ContextMenu.cs b/src/Files.App/Shell/ContextMenu.cs index 132ef0985b1e..2aaee1db7d93 100644 --- a/src/Files.App/Shell/ContextMenu.cs +++ b/src/Files.App/Shell/ContextMenu.cs @@ -163,6 +163,17 @@ public async Task InvokeItem(int itemID) } } + public static async Task WarmUpQueryContextMenuAsync() + { + await new ThreadWithMessageQueue().PostMethod(() => + { + // Create a dummy context menu for warming up + var shellItem = ShellFolderExtensions.GetShellItemFromPathOrPidl("C:\\"); + Shell32.IContextMenu menu = shellItem.Parent.GetChildrenUIObjects(default, shellItem); + menu.QueryContextMenu(User32.CreatePopupMenu(), 0, 1, 0x7FFF, Shell32.CMF.CMF_NORMAL); + }); + } + #endregion FactoryMethods private void EnumMenuItems( From 3dd215f7c06ad85d0232b25248c927e67a8704cd Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Tue, 4 Apr 2023 17:21:01 +0900 Subject: [PATCH 2/2] Dispose thread --- src/Files.App/Shell/ContextMenu.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Files.App/Shell/ContextMenu.cs b/src/Files.App/Shell/ContextMenu.cs index 2aaee1db7d93..f70b74688d60 100644 --- a/src/Files.App/Shell/ContextMenu.cs +++ b/src/Files.App/Shell/ContextMenu.cs @@ -165,13 +165,15 @@ public async Task InvokeItem(int itemID) public static async Task WarmUpQueryContextMenuAsync() { - await new ThreadWithMessageQueue().PostMethod(() => + var thread = new ThreadWithMessageQueue(); + await thread.PostMethod(() => { // Create a dummy context menu for warming up var shellItem = ShellFolderExtensions.GetShellItemFromPathOrPidl("C:\\"); Shell32.IContextMenu menu = shellItem.Parent.GetChildrenUIObjects(default, shellItem); menu.QueryContextMenu(User32.CreatePopupMenu(), 0, 1, 0x7FFF, Shell32.CMF.CMF_NORMAL); }); + thread.Dispose(); } #endregion FactoryMethods