private async Task LoadNextPackageChunk() { ErrorMessage = null; IsEditable = false; var tokenSource = new CancellationTokenSource(); CurrentCancellationToken = tokenSource; List <PackageItem> data = new List <PackageItem>(); try { data = await _packageFinder.LoadNextPackageSet(tokenSource.Token); } catch (Exception e) { ErrorMessage = e.Message; } foreach (var item in data) { NuGetPackageResults.Add(item); } OnPropertyChanged("NuGetPackageResults"); if (CurrentCancellationToken == tokenSource) { CurrentCancellationToken = null; } tokenSource.Dispose(); IsEditable = true; }
public MainWindowViewModel() { ChangeSourceCommand = new CustomCommand(async(source) => { NuGetPackageResults.Clear(); _packageFinder = new PackageFinder(source as string); await LoadNextPackageChunk(); SelectedPackage = NuGetPackageResults.Count > 0 ? NuGetPackageResults[0] as PackageItem : null; }); LoadNextPackageSet = new CustomCommand( (p) => _packageFinder.HasMoreData && IsEditable, async(p) => { await LoadNextPackageChunk(); } ); CancelCommand = new CustomCommand( (p) => !IsEditable && CurrentCancellationToken != null, (p) => { CurrentCancellationToken.Cancel(); IsEditable = true; } ); ChangeSourceCommand.Execute(Sources[1]); }