mirror of
https://github.com/rmcrackan/Libation.git
synced 2025-12-23 22:17:52 -05:00
Fix possible race error on startup with autoscan
This commit is contained in:
@@ -12,6 +12,7 @@ namespace LibationAvalonia.ViewModels
|
||||
{
|
||||
public partial class MainVM : ViewModelBase
|
||||
{
|
||||
public Task? BindToGridTask { get; set; }
|
||||
public ProcessQueueViewModel ProcessQueue { get; } = new ProcessQueueViewModel();
|
||||
public ProductsDisplayViewModel ProductsDisplay { get; } = new ProductsDisplayViewModel();
|
||||
|
||||
@@ -43,6 +44,13 @@ namespace LibationAvalonia.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
//Prevent race condition which can occur if an auto-scan
|
||||
//completes before the initial grid binding completes.
|
||||
if (BindToGridTask is null)
|
||||
return;
|
||||
else if (BindToGridTask.IsCompleted is false)
|
||||
await BindToGridTask;
|
||||
|
||||
await Task.WhenAll(
|
||||
SetBackupCountsAsync(fullLibrary),
|
||||
Task.Run(() => ProductsDisplay.UpdateGridAsync(fullLibrary)));
|
||||
|
||||
@@ -165,9 +165,10 @@ namespace LibationAvalonia.Views
|
||||
if (QuickFilters.UseDefault)
|
||||
await vm.PerformFilter(QuickFilters.Filters.FirstOrDefault());
|
||||
|
||||
await Task.WhenAll(
|
||||
ViewModel.BindToGridTask = Task.WhenAll(
|
||||
vm.SetBackupCountsAsync(initialLibrary),
|
||||
Task.Run(() => vm.ProductsDisplay.BindToGridAsync(initialLibrary)));
|
||||
await ViewModel.BindToGridTask;
|
||||
}
|
||||
|
||||
public void ProductsDisplay_LiberateClicked(object _, LibraryBook[] libraryBook) => ViewModel.LiberateClicked(libraryBook);
|
||||
|
||||
Reference in New Issue
Block a user