I am trying to accomplish a task which I am stuck at and need your help on.
I have made an Web Form website in Visual Studio 2015.
I have a BUTTON on a page and a DIV which shows result from web requests.
I am calling GetAsync on three url and making 3 web requests. Lets name them Request1, Request2 and Request3.
Now let's suppose, Request1 takes 1 seconds, Request2 takes 5seconds and Request3 takes 10 seconds to get data.
What happens is that the website completes all async task first and then shows the data.
I want data to be showed as first downloaded first show basis.
private async Task PerformSearchAsync()
{
HttpClient client = new HttpClient();
List<string> urlList = SetUpURLList();
IEnumerable<Task<RootObject>> downloadTasksQuery =
from url in urlList select ProcessURL(url, client);
List<Task<RootObject>> downloadTasks = downloadTasksQuery.ToList();
while (downloadTasks.Count > 0)
{
// Identify the first task that completes.
Task<RootObject> firstFinishedTask = await Task.WhenAny(downloadTasks);
// ***Remove the selected task from the list so that you don't
// process it more than once.
downloadTasks.Remove(firstFinishedTask);
// Await the completed task.
RootObject rootObject = await firstFinishedTask;
DisplayResult(rootObject);
}
}
private void DisplayResult(RootObject rootObject)
{
string s = "Name: "+rootObject.name+ " <span><img src =\"http://"+rootObject.logo+"\" alt=\"Source Logo\" style=\"width:16px;height:16px;\"></span>";
Source.InnerHtml += s;
}
So what I want to do is if Request1 is completed show its result on web page immediately and then when Request2 or Request3 is completed update the webpage with that request's result
Thank you in advance