KeinMitleid

FP Subforums v3

Nov 2nd, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Net;
  4. using System.Net.Http;
  5. using System.Threading.Tasks;
  6.  
  7. class Program
  8. {
  9.     static void Main()
  10.     {
  11.         int[] subforums = {
  12.             6, 15, 16, 36, 38, 40, 46, 51, 56, 60, 62, 64, 65, 66, 75, 76, 107,
  13.             110, 189, 198, 240, 243, 262, 277, 315, 316, 339, 353, 361, 383,
  14.             384, 385, 389, 391, 393, 394, 396, 397, 401, 403, 408, 409, 411,
  15.             412, 414, 415 };
  16.  
  17.         ServicePointManager.DefaultConnectionLimit = 100;
  18.         var client = new HttpClient();
  19.     var tasks = new Task<string>[subforums.Length];
  20.         var time = new Stopwatch();
  21.  
  22.         time.Start();
  23.  
  24.         Parallel.For(0, subforums.Length, subforum =>
  25.             tasks[subforum] = client.GetStringAsync(
  26.                 "http://www.facepunch.com/forumdisplay.php?f=" +
  27.         subforums[subforum]));
  28.  
  29.         Task.WaitAll(tasks);
  30.  
  31.         time.Stop();
  32.  
  33.         Console.WriteLine("Request completed in {0} seconds.",
  34.             ((float)time.ElapsedMilliseconds / 1000).ToString("F3"));
  35.         Console.Write("Press any key to continue . . . ");
  36.         Console.ReadKey();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment