1

I'm using the following code to count the number of rows in an html table, store that number to use in a for loop which extracts text out of a <td> in each row.

Table myTable = browser.Div(Find.ById("resultSpan")).Table(Find.First());

            int numRows = myTable.TableRows.Count;
            List<string> myList = new List<string>();
            for (int i = 1; i < numRows; i++)
            {
                myList.Add(myTable.TableRows[i].TableCells[1].Text);  
            }

I placed a label control on my form and I basically want it to increment in real time so I can see how fast the program is parsing the data.

On average I'm dealing with ~2000 rows, so it takes a long time, and I want to be able to see the status. The above code is using WatiN, but I'm sure this is a C# question.

Edit This was easier than I thought-

for (int i = 1; i < numRows; i++)
            {
                myList.Add(myTable.TableRows[i].TableCells[1].Text);  
                label1.Text = i.ToString();
            }
The Muffin Man
  • 19,585
  • 30
  • 119
  • 191

1 Answers1

1

You might want to use BackgroundWorker here so you are not blocking your UI and so you can provide status update through the BackgroundWorker

Dennis Smit
  • 1,168
  • 8
  • 12
  • this program has one job, so blocking the UI isn't an issue, but will using the BackgroundWorker speed up the parsing of the html? – The Muffin Man Mar 02 '11 at 03:42
  • I won't speed the parsing up, but it will give you a good way to track progress. The reason why you can't update the label is because you are running your heavy task on the UI thread, so it has to wait till your task is done. If you are able to cut your HTML it multiple parts you could use PLINQ [(Parallel.For)](http://www.codeproject.com/KB/cs/aforge_parallel.aspx) to make it multicore (processor cores) aware and that might speed processing up. – Dennis Smit Mar 02 '11 at 03:46