コード例 #1
0
        protected void ThreadProc(object data)
        {
            WorkerData     d       = (WorkerData)data;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Timeout         = requestTimeout;
            request.KeepAlive       = false;
            request.ProtocolVersion = HttpVersion.Version10;
            Uri uri = new Uri(url);

            if (UriHostNameType.Dns == Uri.CheckHostName(uri.Host))
            {
                request.Host = uri.Host;
            }

            HttpWebResponse response = null;

            try {
                //todo: try to use request.GetResponseAsync() C# 5
                response = (HttpWebResponse)request.GetResponse();
                DebugOutput(
                    "(" + Thread.CurrentThread.ManagedThreadId + ")" +
                    " Response " +
                    "[" + d.iterateNum + "|" + d.threadNum + "/" + d.threadsCount + "]: " +
                    response.StatusCode
                    );
                if (null != onWorkResult)
                {
                    onWorkResult(this, new WorkerResult(d, response, ""));
                }
            } catch (Exception e) {
                DebugOutput(
                    "(" + Thread.CurrentThread.ManagedThreadId + ")" +
                    " Error " +
                    "[" + d.iterateNum + "|" + d.threadNum + "/" + d.threadsCount + "]: " +
                    e.Message
                    );
                if (null != onWorkResult)
                {
                    onWorkResult(this, new WorkerResult(d, null, e.Message));
                }
            } finally {
                if (null != response)
                {
                    response.Close();
                }
            }
        }
コード例 #2
0
ファイル: Worker.cs プロジェクト: cloud3g/WebStress
 public WorkerResult(WorkerData data, HttpWebResponse response, string error)
 {
     this.data     = data;
     this.response = response;
     this.error    = error;
 }