S
S
Sergey Karbivnichy2017-01-15 21:58:51
.NET
Sergey Karbivnichy, 2017-01-15 21:58:51

How to download several web pages at the same time in c#?

There is a site site.com It has many pages like site.com/id1 ... site.com/id100000. I need to download these pages. But one page at a time (even at a speed of 100Mb) they will take a long time to download. How to implement a program so that it loads at once, for example, 10 pages each?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Zaitsev, 2017-01-18
@nithrous

Quick way:

var urls = new List<string>()
{
    "http://google.com",
    "http://yandex.com"
}
Parallel.ForEach(urls, (url) => 
{
    // код получения и обработки.
});

Unlike the implementation via Thread, this one is simpler and consumes fewer resources.

P
Peter, 2017-01-15
@petermzg

Multithreaded programming. Thread class.

A
Artem, 2017-01-16
@Etrimus

Read about async / await, a very easy topic to understand if you write simple applications, like your task.
https://habrahabr.ru/post/139734/
https://habrahabr.ru/interesting/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question