What I am trying
In my WPF I crawl my internal network and see if an IP/URL can be accessed. So I call 255 IPs with DownloadStringAsync
in a loop. Now, whenever I receive a response or a timeout I want to update my progressbar (which has a max of 255). My code seems to work for the first x (I believe something like 10-15) IPs as I see the progressbar moving
The Call-Loop
try
{
while (i < 255)
{
var client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(GetInfo);
client.DownloadStringAsync(new Uri("http://" + myIPNet + "." + i + ":1400/status/topology"));
i++;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
The GetInfo Function
private void GetInfo(object sender, DownloadStringCompletedEventArgs e)
{
/* Each call, count up Global Ip Counter and move progressBar */
countIps++;
pbSearch.Value = countIps;
/* Do Stuff with e.Result */
...
/* Check if we have all IPs in net already */
if (countIps == 255)
{
/* Reset progressBar */
pbSearch.Value = 0;
/* Enable Button */
btnGetAll.IsEnabled = true;
}
}
I found this Asynchronous File Download with Progress Bar and I think I understand this answer https://stackoverflow.com/a/9459441/1092632 but this has the progressbar updated for one download in progress, any ideas on how to "convert" this to my case?