当前位置: 移动技术网 > IT编程>移动开发>WP > windows phone 中HttpWebRequest异步线程同步

windows phone 中HttpWebRequest异步线程同步

2018年03月22日  | 移动技术网IT编程  | 我要评论

dnf超级助手下载,延津县人民政府网,长得轻浮也违章

public class RequestState
    {
        public HttpWebRequest request { get; set; }
        public HttpWebResponse response { get; set; }
        public Stream streamResponse { get; set; }
    }

    public class HttpHelper
    {
        public delegate void GetData(string text);

        public event GetData Data;

        public class HttpCallBackEvent
        {
            public HttpWebRequest request;
            public byte[] file;
            public string name;
            public string fileName;

        }


        public static ManualResetEvent allDone = new ManualResetEvent(false);

        public Stream HttpGet(string url )
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
            request.Method = "GET";

            RequestState state = new RequestState();
            state.request = request;

            request.BeginGetResponse(webResponseCallack,state);
            allDone.Reset();    www.2cto.com
            allDone.WaitOne();

            return state.streamResponse;
        }

        private void webResponseCallack(IAsyncResult result)
        {
            try             {
                RequestState state = (RequestState)result.AsyncState;
                HttpWebRequest request = state.request;
                state.response = (HttpWebResponse)request.EndGetResponse(result);
                state.streamResponse = state.response.GetResponseStream();
               
            }
            catch             { }
            finally             {
                allDone.Set();
            }
        }


}


作者:修修

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网