Esempio n. 1
0
        private async Task BuildVideoList(object x)
        {
            cancelSource = new CancellationTokenSource();

            YoutubeViewHeader = "YT Search: " + SearchTermText;

            await Task.Run(async() =>
            {
                var links = await _youtube.SearchAsync(SearchTermText);

                var ytVids = new List <YoutubeVideo>();

                try
                {
                    for (int i = 0; i < links.Count; i++)
                    {
                        if (!cancelSource.IsCancellationRequested)
                        {
                            ytVids.Add(new YoutubeVideo(links[i]));
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    IsSearching   = false;
                    VideosVisible = true;

                    if (!cancelSource.IsCancellationRequested)
                    {
                        VideoList = new ListCollectionView(ytVids);
                    }
                }
            }, cancelSource.Token);
        }