private async Task Search() { if (IsBusy) { return; } IsBusy = true; _searchInitialized = true; _observableResults.Clear(); Results = null; SelectedResult = null; var mediaTypes = MediaTypes.SelectedItems.Any() ? MediaTypes.SelectedItems.Select(mt => mt.Item).Aggregate((mt1, mt2) => mt1 | mt2) : Novaroma.MediaTypes.All; await Novaroma.Helper.RunTask(async() => { await _engine .AdvancedSearchInfo(Query, mediaTypes, ReleaseYearStart, ReleaseYearEnd, RatingMin, RatingMax, VoteCountMin, VoteCountMax, RuntimeMin, RuntimeMax, Genres.SelectedItems) .ContinueWith(async t => { var results = new List <InfoSearchMediaViewModel <IAdvancedInfoSearchResult> >(); t.Result.ToList() .ForEach(r => results.Add(new InfoSearchMediaViewModel <IAdvancedInfoSearchResult>(_engine, _exceptionHandler, DialogService, r, _directory, _isParentDirectory))); if (ExcludeExisting) { var existingMedias = await _engine.GetMedias(results.Select(r => r.SearchResult.ImdbId)); results = results.Where(r => existingMedias.All(em => em.ImdbId != r.SearchResult.ImdbId)).ToList(); } results.ForEach(_observableResults.Add); Results = _observableResults; Application.Current.Dispatcher.Invoke(CommandManager.InvalidateRequerySuggested); if (_results.Any()) { SelectedResult = _results.First(); } }); }, _exceptionHandler); IsBusy = false; }