Question

There is a method which gets a server response with

var response = (HttpWebResponse)await request.GetResponseAsync();

There's additional code to set up the request. I wrapped this in an async method. This method takes a url as parameter. The call for this method is wrapped with a method again, which constructs the actual url.

Imagine the final methodcall looks like this:

string resultString = await GetResultString(parameter);

Then the following problem occured: I want to send multiple requests at the same time. I've got a list of parameters. I did it like this:

var tasks = new List<Task<string>>();
foreach(parameter in parameters)
{
    tasks.Add(GetResultString(parameter));
}
List<string> resultStrings = await TaskEx.WhenAll(tasks);

That also works fine. But the number of requests is variable. So it could be 10 requests. But it's also possible that you fire 10.000 requests or even 100.000. So I thought about monitoring the progress in a progress bar. But how could I do this? I already had a look on this piece of code but I can't get any idea of how I could use that for my code. I need to raise an event, everytime a task has finished. But how when there is not any callback when a task finished?

Thanks and regards

PS: could somebody tell me how to use copy & paste for code without putting four spaces in front of every single line of code? I couldn't get any help out of the advanced help. I just can't get it work. And I'm sorry that my English is not too perfect. I'm German. :-)

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top