private void GrapFilms(object sender, List <PossibleFilm> films) { var worker = sender as BackgroundWorker; var numFilms = films.Count; var count = 1; foreach (var film in films) { if (UClosePending) { return; } var percent = (count++ / (double)numFilms) * 100; worker.ReportProgress((int)percent, film.Path); var newFilm = ImdbFilm.GetFilmByName(film.Title); if (newFilm != null) { newFilm.FilmPath = film.Path; if (Regex.IsMatch(newFilm.Title, film.Title.Trim(), RegexOptions.IgnoreCase)) { _films.Add(new FilmResult(newFilm) { PossibleErrors = false }); } else { var f = new FilmResult(newFilm) { PossibleErrors = true }; _films.Add(f); } } else { var f = new FilmResult() { FilmPath = film.Path, PossibleErrors = null }; _films.Add(f); } } }
private void ExecuteScan(string url) { var bg = new BackgroundWorker(); bg.WorkerReportsProgress = true; panel1.Enabled = false; panel2.Visible = true; bg.DoWork += (s, ee) => { var worker = s as BackgroundWorker; worker.ReportProgress(100, ImdbFilm.GetFilmByUrl(url)); }; bg.ProgressChanged += (s, ee) => { if (ee.UserState != null) { var path = Film.FilmPath; var error = Film.PossibleErrors; Film = new FilmResult((Film)ee.UserState) { FilmPath = path, PossibleErrors = error }; } else if ( MessageBox.Show("No film found!\n Check URL!", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) == DialogResult.Retry) { Scan(url); } }; bg.RunWorkerCompleted += (s, ee) => { populate(); panel1.Enabled = true; }; bg.RunWorkerAsync(); }