예제 #1
0
파일: Test.cs 프로젝트: gyn7561/AsyncHttp
        public void Callback()
        {
            AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
            var             request         = new HttpRequest();

            request.Uri = new Uri("http://www.w3school.com.cn");
            var html = asyncHttpClient.GetString(request);

            TestContext.WriteLine(html);
            var count     = 0;
            var testCount = 100;

            for (int i = 0; i < testCount; i++)
            {
                asyncHttpClient.Execute(request, (res) =>
                {
                    res.BodyStream.ReadAsString((str) =>
                    {
                        TestContext.WriteLine("thread id:" + Thread.CurrentThread.ManagedThreadId);

                        lock (this)
                        {
                            count++;
                        }
                    });
                });
            }

            while (count != testCount)
            {
                Thread.Sleep(10);
            }
        }