private void OnSearchTextChanged() { searchTaskCancellationTokenSource?.Cancel(); var txt = SearchText; if (string.IsNullOrWhiteSpace(txt)) { FilteredSongsLoader.Items = Enumerable.Empty <FullSongInfo>(); return; } searchTaskCancellationTokenSource = new CancellationTokenSource(); searchTask = Task.Run(async() => { searchPlaylist = await database.Search(txt, searchTaskCancellationTokenSource.Token); return(await Map(searchPlaylist.Playlist.Songs)); }) .ContinueWith( task => dispatcher.Invoke(() => { FilteredSongsLoader.Items = task.Result; LoadPlaylistCommand.Refresh(); }), searchTaskCancellationTokenSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); this.InvokePropertyChanged(PropertyChanged, nameof(IsLoading)); searchTask.ContinueWith(_ => dispatcher.Invoke(() => this.InvokePropertyChanged(PropertyChanged, nameof(IsLoading)))); }
private void LoadPlaylistExecute(object sender, ExecutedRoutedEventArgs e) { var cmd = new LoadPlaylistCommand(MainWindowViewModel.Instance.Playlist); cmd.Execute(null); }