lundi 31 août 2015

how to shorten source code using whenall in order to optimize speed

I have used following code and its supposed to be used for calling more than 100,000 urls .

As its taking long time to finish the process , I am trying to find a better way to optimize the code.

I have read other questions like mine and few people suggested to remove toarray but there were example of how to do it.

Any comments would be appreciated.

private async Task ProcessAllURLSAsync(List<string> urlList)
{
    IEnumerable<Task> CallingTasksQuery =
        from url in urlList select ProcessURLAsync(url);

    Task[] CallingTasks = CallingTasksQuery.ToArray();

    await Task.WhenAll(CallingTasks);
}

private async Task ProcessURLAsync(string url)
{
    await CallURLAsync(url);
}

private async Task CallURLAsync(string url)
{
    var content = new MemoryStream();
    var webReq = (HttpWebRequest)WebRequest.Create(url);
    using (WebResponse response = await webReq.GetResponseAsync())
    {
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire