I have many url's (about 800) to download from web. I have a class: HttpDownloader.cs that uses with HttpWebRequest class to download and get the html pages. After that I do pharsing to the pages by Regex.
I want to use BackgroundWorker component, But I don't know how to do It for all the pages. by a loop, or something like that.
My code:
I tried use with ThreadPool, and it realy did problems. I tried with 4 url's and it didn't work.
foreach (string link in MyListOfUrls)
{
ThreadPool.QueueUserWorkItem((o) => {
HttpDownloader httpDownload = new HttpDownloader(link);
string htmlDoc = httpDownload.GetPage();//get the html of the page
HtmlDocument doc=doc.LoadHtml(htmlDoc);//load html string to doc for pharsing
DoPharsing();//my func for pharsing
Save();//save into dataBase
});
}
Because I use with connection to dataBase and DataTable in my func I get an exception when I use ThreadPool:
"Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation."
So, I can't get a data from the DataTable. maybe I need to download all, and afterwards do pharsing and save??
How can I Change it to Async by BackgroundWorker component??
p.s. Don't advice me with Async Tpc, because I didn't manage to download it.
Thanks