1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Diagnostics;
using System.IO;


namespace webpound
{
    class Program
    {
        static long count = 0;
        static void Main(string[] args)
        {
            var s = new Stopwatch();
            var wc = new WebClient();
            int time = 100, mthread=0;

            if (args.Count() == 0)
            {
                Console.WriteLine("[1 (for single) [ms time]] url");
                return;
            }
            string url = null;
            bool useSingle = false;
            if (args.Count() == 1)
            {
                url = args[0];;
            }
            else if (args.Count() == 2)
            {
                useSingle = args[0] == "1";
                url = args[1];
            }
            else if (args.Count() == 3)
            {
                useSingle = args[0] == "1";
                time = int.Parse(args[1]);
                url = args[2];
            }
            else
            {
                throw new Exception();
            }

            var uri = new Uri(url);
            wc.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
            wc.DownloadStringCompleted += DownloadStringCompletedEventHandler;
            //wc.DownloadProgressChanged += DownloadProgressChangedEventHandler;
            wc.DownloadString(uri);
            wc.DownloadStringAsync(uri);

            while (System.Threading.Interlocked.Read(ref count)==0)
            {
                System.Threading.Thread.Sleep(1);
            }
            count = 0;
            WebException ex1 = null;
            s.Start();
            try
            {
                while (s.ElapsedMilliseconds < time)
                {
                    if (useSingle)
                    {
                        wc.DownloadString(url);
                        count++;
                    }
                    else
                    {
                        var wwc = new WebClient();
                        wwc.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
                        wwc.DownloadStringCompleted += DownloadStringCompletedEventHandler;
                        var url2 = url + mthread.ToString();
                        wwc.DownloadStringAsync(new Uri(url2));
                        mthread++;
                        System.Threading.Thread.Sleep(1);
                    }
                }
            }
            catch(WebException ex)
            {
                ex1 = ex;
            }
            var mycount = count;
            s.Stop();
            if (ex1 == null)
            {
                Console.WriteLine("Finished with {0}/{1} in {2}", mycount,mthread, s.ElapsedMilliseconds);
            }
            else
            {
                var aa = new StreamReader(ex1.Response.GetResponseStream()).ReadToEnd();
                Console.WriteLine(ex1.Message);
                Console.WriteLine("Finished with {0}/{1} in {2}", mycount, mthread, s.ElapsedMilliseconds);
            }
        }

        static void DownloadProgressChangedEventHandler(object sender, DownloadProgressChangedEventArgs e)
        {
        }
        static void DownloadStringCompletedEventHandler(object sender, DownloadStringCompletedEventArgs e)
        {
            System.Threading.Interlocked.Increment(ref count);
        }
    }
}