Skip to content

Fix: Fixed issue where the app would crash when displaying a large number of items #14559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Files.App.Data.Models
public sealed class ItemViewModel : ObservableObject, IDisposable
{
private readonly SemaphoreSlim enumFolderSemaphore;
private readonly SemaphoreSlim loadPropertiesSemaphore;
private readonly ConcurrentQueue<(uint Action, string FileName)> operationQueue;
private readonly ConcurrentQueue<uint> gitChangesQueue;
private readonly ConcurrentDictionary<string, bool> itemLoadQueue;
Expand Down Expand Up @@ -442,6 +443,7 @@ public ItemViewModel(LayoutPreferencesManager folderSettingsViewModel)
operationEvent = new AsyncManualResetEvent();
gitChangedEvent = new AsyncManualResetEvent();
enumFolderSemaphore = new SemaphoreSlim(1, 1);
loadPropertiesSemaphore = new SemaphoreSlim(100);
dispatcherQueue = DispatcherQueue.GetForCurrentThread();

UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent;
Expand Down Expand Up @@ -1026,6 +1028,9 @@ await Task.Run(async () =>
var loadGroupHeaderInfo = false;
ImageSource? groupImage = null;
GroupedCollection<ListedItem>? gp = null;

// We use the semaphore to limit the number of concurrent processes because loading properties is a heavy process
await loadPropertiesSemaphore.WaitAsync(cts.Token);
try
{
var isFileTypeGroupMode = folderSettings.DirectoryGroupOption == GroupOption.FileType;
Expand Down Expand Up @@ -1143,6 +1148,8 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
}
finally
{
loadPropertiesSemaphore.Release();

if (!wasSyncStatusLoaded)
{
cts.Token.ThrowIfCancellationRequested();
Expand Down