c# - Best way to send many requests in separate threads -


i have send many requests website, process response , return list of tuples. @ end combine lists one.

when in loop takes long. how can use tpl (task parallel library) achieve shortest time? first case multithreading , don't know how should look.

private static htmldocument htmlresult(restclient client, string querystring, int pagenumber) {     var searchrequest = new restrequest("search/json", method.post);     searchrequest.addparameter("query", querystring);      if (pagenumber > 0)     {         searchrequest.addparameter("page", pagenumber);     }      var results = client.execute(searchrequest).content;     var doc = new htmldocument();     doc.loadhtml(regex.unescape(results));     return doc; }  private static ienumerable<tuple<string, string, string, list<string>, double>> resultslist(restclient client, string querystring, int pagenumber) {     var doc = htmlresult(client, querystring, pagenumber);     // process result     return mylist... }  var resultslist = new list<tuple<string, string, string, list<string>, double>>(); (var = 1; <= 1000; i++) {   var list = resultslist(client, querystring, i);   resultslist.addrange(list); } 

edit:// used parallel.for loop , execution time shortened half:

parallel.for(0, pagescount, (i) => resultslist.addrange(resultslist(client, querystring, i))); 

am curious if there faster way achieve goal?


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -