Exemplo n.º 1
0
        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);
            }
        }