I have a progressBar1 in the designer. And i have a loop that i'm reporting the progress but only the user state not the int.
while (index != -1)
{
string firstTag = "<div class=\"CatLinkContainer\">";
string endTag = "\" href";
index = forums.IndexOf(firstTag, index1);
if (index == -1)
continue;
var secondIndex = forums.IndexOf(endTag, index);
result = forums.Substring(index + firstTag.Length + 12, secondIndex - (index + firstTag.Length - 50));
if (result.Contains("forumPage"))
{
int index2 = result.IndexOf("\" href=\"http://ift.tt/1vHpBkn");
result = result.Remove(index2);
System.Threading.Thread.Sleep(1000);
countResults++;
backgroundWorker1.ReportProgress(0, result);
forumsNames.Add(result);
}
index1 = index + 1;
}
The reporting of the result is working fine. But now i'm reporting to the progressBar1 0. I want to calculate somehow the progress and report also to the progressBar1 the percentages.
I added countResults variable int and i did countResults++;
For example in this case there are 33 result items to report the question is how do i calculate so it will get to the 100% ? In other cases could be 1 items to report or 122.
In the backgroundworker progresschanged event i did:
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
toolStripStatusLabel1.Text = e.UserState.ToString();
toolStripProgressBar1.Value = e.ProgressPercentage;
}
The UserState reporting is working fine. But now how do i calculate to report the ProgressPercentage ?
Aucun commentaire:
Enregistrer un commentaire