private void btnUpdateBookRankFromHTML_Click(object sender, EventArgs e) { var selected = (from Book b in lstBooks.SelectedItems select b).ToList(); btnUpdateBookRankFromHTML.Enabled = false; BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += delegate { appendLineToLog("***STARTING " + btnUpdateBookRankFromHTML.VerticalText); foreach (var book in selected.ToList()) { BookHtmlCrawler.Run(this, book, false, true); sleep(); //delay each page visit } }; bgw.RunWorkerCompleted += delegate { appendLineToLog("***FINISHED " + btnUpdateBookRankFromHTML.VerticalText); btnUpdateBookRankFromHTML.Enabled = true; }; bgw.RunWorkerAsync(); }
private void btnUpdateBookDetailFromHtml_Click(object sender, EventArgs e) { btnUpdateBookDetailFromHtml.Enabled = false; BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += delegate { appendLineToLog("***STARTING " + btnUpdateBookDetailFromHtml.VerticalText); var selected = GetSelectedBooks(); foreach (var book in selected) { //skip if dummy detailPageUrl or already has a reviewpage. (perhaps change to avgrating) if (book.detailPageURL == null || book.detailPageURL == "-" || !string.IsNullOrEmpty(book.reviewPageURL)) { appendLineToLog("Skipped " + book.DisplayString + " - detailPageURL invalid or already has reviewPageURL"); continue; } BookHtmlCrawler.Run(this, book, getDetailsAndAuthor: true, getRanks: false); //don't update ranks/stats sleep(); //delay each page visit } }; bgw.RunWorkerCompleted += delegate { appendLineToLog("***FINISHED " + btnUpdateBookDetailFromHtml.VerticalText); btnUpdateBookDetailFromHtml.Enabled = true; }; bgw.RunWorkerAsync(); }