|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Aug 2000
Messaggi: 1209
|
[C#] Eseguire contemporaneamente tutti i Thresad su "Multithread"
Salve,
ho fatto un piccolo script Console Multithread per fare un parser su una pagina Html, ed estrarre tutti i link con class="pippo". Codice:
public static void Main() { Thread t; for (int i = 0; i <= 10; i++) { DataThread data = new DataThread(); t = new Thread(new ParameterizedThreadStart(TestThread)); t.Start(); } Console.ReadLine(); } public static void TestThread(object data) { HtmlWeb htmlWeb = new HtmlWeb(); string sUrl = ""; HtmlDocument doc = htmlWeb.Load("https://www.pagina.com"); foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//a[@class='pippo']")) { sUrl = node.Attributes["href"].Value; if (sUrl != "") { Console.Write(sUrl + "\n"); } } Io vorrei lanciare 10 richieste http e poi il tempo che impiega ciascuna per terminare sono affari suoi, non mi deve bloccare l'esecuzione del prossimo thread e cioè della richiesta http. Come posso fare ? Grazie molte a tutti. |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:21.