From 786a150faf039e2c497d62565cff1e9422af0229 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Wed, 30 Jul 2025 01:33:48 +0000 Subject: [PATCH] Refactor: Improve icon loading in FolderSearch --- .../Utils/Storage/Search/FolderSearch.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Files.App/Utils/Storage/Search/FolderSearch.cs b/src/Files.App/Utils/Storage/Search/FolderSearch.cs index 29042ca0f959..f9bdb77bc6d4 100644 --- a/src/Files.App/Utils/Storage/Search/FolderSearch.cs +++ b/src/Files.App/Utils/Storage/Search/FolderSearch.cs @@ -395,23 +395,24 @@ private ListedItem GetListedItemAsync(string itemPath, WIN32_FIND_DATA findData) if (listedItem is not null && MaxItemCount > 0) // Only load icon for searchbox suggestions { - _ = FileThumbnailHelper.GetIconAsync( - listedItem.ItemPath, - Constants.ShellIconSizes.Small, - isFolder, - IconOptions.ReturnIconOnly | IconOptions.UseCurrentScale) - .ContinueWith((t) => + _ = FilesystemTasks.Wrap(async () => + { + var iconData = await FileThumbnailHelper.GetIconAsync( + listedItem.ItemPath, + Constants.ShellIconSizes.Small, + isFolder, + IconOptions.ReturnIconOnly | IconOptions.UseCurrentScale); + + if (iconData is not null) { - if (t.IsCompletedSuccessfully && t.Result is not null) + await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () => { - _ = FilesystemTasks.Wrap(() => MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () => - { - var bitmapImage = await t.Result.ToBitmapAsync(); - if (bitmapImage is not null) - listedItem.FileImage = bitmapImage; - }, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low)); - } - }); + var bitmapImage = await iconData.ToBitmapAsync(); + if (bitmapImage is not null) + listedItem.FileImage = bitmapImage; + }, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low); + } + }); } return listedItem;