//Event handler for clicking the search button //shows a loading screen and then creates a task to load the results //and display them protected void OnSearchButtonClicked(object sender, EventArgs e) { string searchText = searchEntry.Text.Trim(); if (searchText == null || searchText == "") { return; } //cancel any task that might be running loadingResultsCancellationSource.Cancel(); string msg = ""; if (showRadioButton.Active) { msg = "Searching Shows for " + searchText; } else { msg = "Searching Movies for " + searchText; } showLoadingScreen(msg); //make a new CancellationSource for a new task loadingResultsCancellationSource = new CancellationTokenSource(); var cancelToken = loadingResultsCancellationSource.Token; //Create the task that gets the results from guidebox Task task = new Task(() => { cancelToken.ThrowIfCancellationRequested(); List <Show> shows = new List <Show>(); //tv if (showRadioButton.Active) { //get the results from guidebox shows = GuideBoxAPIWrapper.getTVShowIds(searchText); cancelToken.ThrowIfCancellationRequested(); //populate the thumbnails foreach (var show in shows) { byte[] thumbNail = getThumbNail(show.thumbURL); if (thumbNail != null) { show.thumb = new Gdk.Pixbuf(thumbNail); } } } //movies else { //get the results from guidebox shows = GuideBoxAPIWrapper.getMovieIds(searchText); cancelToken.ThrowIfCancellationRequested(); //populate the thumbnails foreach (var show in shows) { byte[] thumbNail = getThumbNail(show.thumbURL); if (thumbNail != null) { show.thumb = new Gdk.Pixbuf(thumbNail); } } } cancelToken.ThrowIfCancellationRequested(); //show the results Gtk.Application.Invoke(delegate { embeddedWidget = new ShowResultsWidget(this, shows, 0, true); addEmbeddedWidgetToContainer(); }); }, cancelToken); //create the delegate to handle exceptions task.ContinueWith((t) => { Gtk.Application.Invoke(delegate { outputError(t.Exception.InnerException.Message); }); }, TaskContinuationOptions.OnlyOnFaulted); task.Start(); }
//starts a task to load most popular shows or movies from guidebox //then it loads the embeddedWidget protected void getPopShows(int start) { //make a new CancellationSource for a new task loadingResultsCancellationSource = new CancellationTokenSource(); var cancelToken = loadingResultsCancellationSource.Token; //Create the task that gets the results from guidebox Task task = new Task(() => { cancelToken.ThrowIfCancellationRequested(); List <Show> shows = new List <Show>(); //tv if (showRadioButton.Active) { //get the results from guidebox shows = GuideBoxAPIWrapper.getTVShowIds(start, maxShowsInEmbeddedWidget, activeSource); cancelToken.ThrowIfCancellationRequested(); //populate the thumbnails foreach (var show in shows) { byte[] thumbNail = getThumbNail(show.thumbURL); if (thumbNail != null) { show.thumb = new Gdk.Pixbuf(thumbNail); } } } //movies else { //get the results from guidebox shows = GuideBoxAPIWrapper.getMovieIds(start, maxShowsInEmbeddedWidget, activeSource); cancelToken.ThrowIfCancellationRequested(); //populate the thumbnails foreach (var show in shows) { byte[] thumbNail = getThumbNail(show.thumbURL); if (thumbNail != null) { show.thumb = new Gdk.Pixbuf(thumbNail); } } } cancelToken.ThrowIfCancellationRequested(); //show the results Gtk.Application.Invoke(delegate { embeddedWidget = new ShowResultsWidget(this, shows, start, false); addEmbeddedWidgetToContainer(); }); }, cancelToken); //create the delegate to handle exceptions task.ContinueWith((t) => { Gtk.Application.Invoke(delegate { outputError(t.Exception.InnerException.Message); }); }, TaskContinuationOptions.OnlyOnFaulted); task.Start(); }