Ejemplo n.º 1
0
        public IAsyncResult MyBeginXX(AsyncCallback callback)
        {
            var asyncResult = new MyWebRequest(callback, null);
            var request     = WebRequest.Create("https://github.com/");

            new Thread(() =>  //重新启用一个线程
            {
                using (StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()))
                {
                    var str = sr.ReadToEnd();
                    asyncResult.SetComplete(str);//设置异步结果
                }
            }).Start();
            return(asyncResult);//放回一个IAsyncResult
        }