/// <summary> /// Starts the movie import. Sets up UI appropriately and starts a new thread. /// </summary> private void btnMovieImportStart_Click(object sender, EventArgs e) { // Validate the movie filename. blockSubmitIfValidationFails = true; try { txtMovieFileName.Focus(); if (!Validate()) { return; } } finally { blockSubmitIfValidationFails = false; } // Do UI changes, e.g. hide Start button, show Stop button, start progress bar. btnMovieImportStart.Visible = false; btnMovieImportStop.Visible = true; progressBar.Value = 0; progressBar.Visible = true; // Start importer in another thread. movieImporter = new MovieImporter(txtMovieFileName.Text); movieImporter.Completed += new CompletedEventHandler(MovieImportFinished); movieImporter.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged); ThreadPool.QueueUserWorkItem(new WaitCallback(movieImporter.Import)); }
/// <summary> /// Event handler that gets called when the movie import is finished. /// </summary> private void MovieImportFinished(object sender, CompletedEventArgs args) { ImportResult result = args.Result; movieImporter = null; Invoke((Action)(() => { btnMovieImportStart.Visible = true; btnMovieImportStop.Visible = false; progressBar.Visible = false; ImportResultsPopup popup = new ImportResultsPopup(result); popup.ShowDialog(); })); }