Skip to content

Commit 9aca493

Browse files
authored
Stop loading icons when the conflict dialog is closed (#8042)
1 parent 622c197 commit 9aca493

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/Files/Dialogs/FilesystemOperationDialog.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
xmlns:vc="using:Files.Converters"
1212
x:Name="RootDialog"
1313
Title="{x:Bind ViewModel.Title, Mode=OneWay}"
14+
Closing="RootDialog_Closing"
1415
CornerRadius="{StaticResource OverlayCornerRadius}"
1516
DefaultButton="Primary"
1617
IsPrimaryButtonEnabled="{x:Bind ViewModel.PrimaryButtonEnabled, Mode=OneWay}"

src/Files/Dialogs/FilesystemOperationDialog.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ private void Grid_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
107107
(sender as Grid).FindAscendant<ListViewItem>().ContextFlyout = ItemContextFlyout;
108108
}
109109
}
110+
111+
private void RootDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
112+
{
113+
ViewModel.ClosingCommand.Execute(null);
114+
}
110115
}
111116

112117
public interface IFilesystemOperationDialogView

src/Files/ViewModels/Dialogs/FilesystemOperationDialogViewModel.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Files.DataModels;
22
using Files.Dialogs;
33
using Files.Enums;
4+
using Files.Extensions;
45
using Files.Helpers;
56
using Microsoft.Toolkit.Mvvm.ComponentModel;
67
using Microsoft.Toolkit.Mvvm.Input;
@@ -9,6 +10,7 @@
910
using System.Collections.Generic;
1011
using System.Collections.ObjectModel;
1112
using System.Linq;
13+
using System.Threading;
1214
using System.Threading.Tasks;
1315
using System.Windows.Input;
1416
using Windows.UI.Xaml.Controls;
@@ -106,16 +108,28 @@ public bool MustResolveConflicts
106108

107109
public ICommand ApplyToAllCommand { get; private set; }
108110

111+
public ICommand ClosingCommand { get; private set; }
112+
113+
private CancellationTokenSource ClosingCts { get; }
114+
109115
public FilesystemOperationDialogViewModel()
110116
{
117+
ClosingCts = new CancellationTokenSource();
118+
111119
// Create commands
112120
PrimaryButtonCommand = new RelayCommand(PrimaryButton);
113121
SecondaryButtonCommand = new RelayCommand(SecondaryButton);
122+
114123
LoadedCommand = new RelayCommand(() =>
115124
{
116125
UpdatePrimaryButtonEnabled();
117126
});
118127

128+
ClosingCommand = new RelayCommand(() =>
129+
{
130+
ClosingCts.Cancel();
131+
});
132+
119133
ApplyToAllCommand = new RelayCommand<string>(s =>
120134
{
121135
ApplyConflictOptionToAll((FileNameConflictResolveOptionType)int.Parse(s));
@@ -284,29 +298,30 @@ public static FilesystemOperationDialog GetDialog(FilesystemItemsOperationDataMo
284298
};
285299
viewModel.Items = new ObservableCollection<FilesystemOperationItemViewModel>(itemsData.ToItems(
286300
viewModel.UpdatePrimaryButtonEnabled, viewModel.OptionGenerateNewName, viewModel.OptionReplaceExisting, viewModel.OptionSkip));
287-
_ = LoadItemsIcon(viewModel.Items);
301+
_ = LoadItemsIcon(viewModel.Items, viewModel.ClosingCts.Token);
288302
FilesystemOperationDialog dialog = new FilesystemOperationDialog(viewModel);
289303

290304
return dialog;
291305
}
292306

293-
private static async Task LoadItemsIcon(IEnumerable<FilesystemOperationItemViewModel> items)
307+
private static async Task LoadItemsIcon(IEnumerable<FilesystemOperationItemViewModel> items, CancellationToken token)
294308
{
295-
await Task.Run(() => Task.WhenAll(items.ToList().Select(async (item) =>
309+
await items.ParallelForEach(async (item) =>
296310
{
297311
try
298312
{
299313
var iconData = await FileThumbnailHelper.LoadIconFromPathAsync(item.SourcePath, 64u, Windows.Storage.FileProperties.ThumbnailMode.ListView);
300314
if (iconData != null)
301315
{
316+
if (token.IsCancellationRequested) return;
302317
await Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, async () =>
303318
{
304319
item.ItemIcon = await iconData.ToBitmapAsync();
305320
});
306321
}
307322
}
308323
catch { }
309-
})));
324+
}, 10, token);
310325
}
311326
}
312327
}

0 commit comments

Comments
 (0)