I want my forms application to start multiple threads to download the source code from a site in parallel.
This is just a part of the main application.
Link to the picture: http://www.abload.de/img/pic9aym7.png
I’m not allowed to post images.
private void buttonstart_Click(object sender, EventArgs e)
{
//check the list below
}
private void buttonabort_Click(object sender, EventArgs e)
{
//should always could abort the process/threads. (close all webcontrols ect)
}
- It should start to read the numeric in the box.
- foreach number it should open a webbrowser or httpwebrequest to download some source code and count the runs (in this example 4 runs).
so if the website is like “http://www.bla.com/”, it should add the run to the end of the variable (http://www.bla.com/1-4). -
Parse the source into different strings. (strWebsiteString1, strWebsiteString2, and so on. I’ll need them later)
-
if that is done, it should read some tables(from the strings) and parse them in to arrays. (same here array1[3], array2[3], for future use)
To get the tables I think I will use htmlagilitypack.
I’ve already coded this htmlagilitything for console. I just need to rebuild it for my forms application, and change console writeline to put it in some arrays.But I’m open to other/better solution.
- All my data I’ve parsed into the arrays should now been shown in the datagridcolumns.
Each run will get its own row.
But when I try to add items into the comboboxcolumn, I get errors at each and every comboboxcolumn. - To get them in the right order and to know which browser data it is from, column1 will get the number of runs.
I’ve already tried by myself.
I get stuck with the threads respectively crossthreading.
And the datagridview makes a lot trouble too.
Do me a favour and help me to solve this problem and show me maybe show a snippet/sample what could help me.
This is a clear example demonstrating what I’ve stated on my comment above. It uses lock instead of Mutex but you’ll get the point. It’s a simple code using multi-threaded Job producers all adding informations to the same (locked) resource and one consumer running once every second to interact with a form control -ListBox in this case- and clear the jobs cache.
You’ll find further informations here http://www.albahari.com/threading/part2.aspx
And here you can find an example using the Dictionary to hold several jobs results: