Skip to content

Commit 5b1fad8

Browse files
author
Carl Chang
committed
fix objectlist add task synchronization;
1 parent c226546 commit 5b1fad8

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

Helpers/LoadHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ public static IEnumerable<ObjectInfo> GetAll(string path) {
631631

632632
public static void CacheFolder(string path, ref CancellationTokenSource tknSrc, object tknLock, Action<string, int, int> callback) {
633633
tknSrc?.Cancel();
634-
tknSrc?.Dispose();
635634
Monitor.Enter(tknLock);
636635
tknSrc = new CancellationTokenSource();
637636
var count = 0;

Helpers/ObservableClasses.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class ObservableKeyedCollection<TKey, TItem> : KeyedCollection<TKey, TIte
2424
/// Needs either a delegate or a property name to get the key from the child item.
2525
/// Using a delegate should be faster than the property name which will use reflection.
2626
/// If TItem implements both INotifyCollectionChanged and INotifyCollectionChanging, the name of the key property is also needed for key updating to work.
27+
/// <para>Be aware that this is not thread-safe.</para>
2728
/// </summary>
2829
public ObservableKeyedCollection(Func<TItem, TKey> getKeyFunc = null, string keyPropName = null, IEnumerable<TItem> collection = null) {
2930
if (getKeyFunc == null && keyPropName == null)

MainWindow.xaml.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public string CurrentPath {
4545
virWrapPanel.Children.Cast<ContentPresenter>().Count(cp => ((ObjectInfo)cp.Content).SourcePaths?.Length > 0) * 200 + App.Random.Next(2, 7) * 1000));
4646

4747
internal CancellationTokenSource tknSrc_LoadThumb;
48-
internal readonly object lock_LoadThumb = new object();
48+
private readonly object lock_LoadThumb = new object();
4949

5050
private VirtualizingWrapPanel virWrapPanel;
5151
private Rect lastWindowRect;
@@ -96,7 +96,6 @@ private async void MainWin_Closing(object sender, CancelEventArgs e) {
9696
Setting.ThumbnailSize.PropertyChanged -= ThumbnailSizeChanged;
9797

9898
tknSrc_LoadThumb?.Cancel();
99-
tknSrc_LoadThumb?.Dispose();
10099
while (tknSrc_LoadThumb != null) { await Task.Delay(100); }
101100

102101
Dispatcher.Invoke(() => ObjectList.Clear());
@@ -156,10 +155,13 @@ private void openFolderPrompt() {
156155
OpenFolderDialog(this, path => Task.Run(() => LoadPath(path)));
157156
}
158157

159-
private async void callback_AddToImageList(ObjectInfo objInfo) {
158+
/// <summary>
159+
/// This needs to be synchronous for the cancallation to work.
160+
/// </summary>
161+
private void callback_AddToImageList(ObjectInfo objInfo) {
160162
//exclude non-image items in immersion mode
161163
if (Setting.ImmersionMode && objInfo.SourcePaths == null) {
162-
objInfo.SourcePaths = await GetSourcePathsAsync(objInfo);//update needed to exclude items that do not have thumbs
164+
objInfo.SourcePaths = GetSourcePaths(objInfo);//update needed to exclude items that do not have thumbs
163165
if (objInfo.SourcePaths == null || objInfo.SourcePaths.Length == 0)
164166
return;
165167
}
@@ -220,7 +222,6 @@ internal void LoadPath(ObjectInfo objInfo, ViewWindow viewWin = null) {
220222
//directory -> load thumbs
221223
try {
222224
tknSrc_LoadThumb?.Cancel();
223-
tknSrc_LoadThumb?.Dispose();
224225
Monitor.Enter(lock_LoadThumb);
225226
tknSrc_LoadThumb = new CancellationTokenSource();
226227
preRefreshActions();
@@ -253,7 +254,6 @@ internal void LoadPath(ObjectInfo objInfo, ViewWindow viewWin = null) {
253254
//archive itself -> extract and load thumbs
254255
try {
255256
tknSrc_LoadThumb?.Cancel();
256-
tknSrc_LoadThumb?.Dispose();
257257
Monitor.Enter(lock_LoadThumb);
258258
tknSrc_LoadThumb = new CancellationTokenSource();
259259
preRefreshActions();
@@ -265,7 +265,6 @@ internal void LoadPath(ObjectInfo objInfo, ViewWindow viewWin = null) {
265265
CldInfoCallback = callback_AddToImageList,
266266
}, tknSrc_LoadThumb);
267267
Dispatcher.Invoke(() => scrollPosition());
268-
//postRefreshActions();
269268
}
270269
finally {
271270
tknSrc_LoadThumb.Dispose();

0 commit comments

Comments
 (0)