Native context menu: wait before querying the menu

This commit is contained in:
Yusyuriv 2024-06-17 05:25:32 +06:00
parent 58e4285953
commit 2e2c1742b0
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0

View file

@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
@ -275,6 +276,10 @@ public static class ShellContextMenuDisplayHelper
contextMenu = (IContextMenu)Marshal.GetTypedObjectForIUnknown(pContextMenu, typeof(IContextMenu));
// Without waiting, some items, such as "Send to > Documents", don't always appear, which shifts item ids
// even though it shouldn't. Please replace this if you find a better way to fix this bug.
Thread.Sleep(200);
hMenu = CreatePopupMenu();
contextMenu.QueryContextMenu(hMenu, 0, ContextMenuStartId, ContextMenuEndId, (uint)ContextMenuFlags.Explore);