Fix exception thrown when uninstalling game
This commit is contained in:
parent
bd81e97037
commit
956c2c3b8a
1 changed files with 20 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
|
@ -21,6 +22,11 @@ public partial class DepotViewModel : ViewModelBase
|
|||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILogger<DepotViewModel> _logger;
|
||||
|
||||
// Serializes loads so overlapping invocations (e.g. a depot load still in flight
|
||||
// when LibraryChanged fires on install/uninstall) never mutate the carousels
|
||||
// concurrently, which corrupts the ObservableCollections.
|
||||
private readonly SemaphoreSlim _loadLock = new(1, 1);
|
||||
|
||||
// ── State ────────────────────────────────────────────────────────────────
|
||||
|
||||
[ObservableProperty] private bool _isLoading;
|
||||
|
|
@ -78,6 +84,20 @@ public partial class DepotViewModel : ViewModelBase
|
|||
|
||||
[RelayCommand]
|
||||
private async Task LoadInternalAsync()
|
||||
{
|
||||
await _loadLock.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
await LoadCoreAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_loadLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadCoreAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
HasError = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue