示例#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);
            }
        }