Пример #1
0
        private void WebResponseCallback(IAsyncResult asyncResult)
        {
            WebReadState asyncState = (WebReadState)asyncResult.AsyncState;

            try
            {
                asyncState.readStream = asyncState.webRequest.EndGetResponse(asyncResult).GetResponseStream();
                asyncState.buffer     = new byte[0x186a0];
                asyncState.readStream.BeginRead(asyncState.buffer, 0, asyncState.buffer.Length, new AsyncCallback(this.WebReadCallback), asyncState);
            }
            catch (WebException exception)
            {
                base.Dispatcher.Invoke(DispatcherPriority.Render, new WebRequestErrorDelegate(this.WebRequestError), exception);
            }
        }
Пример #2
0
 private void GetGifStreamFromHttp(Uri uri)
 {
     try
     {
         WebReadState state = new WebReadState
         {
             memoryStream = new MemoryStream(),
             webRequest   = WebRequest.Create(uri)
         };
         state.webRequest.Timeout = 0x2710;
         state.webRequest.BeginGetResponse(new AsyncCallback(this.WebResponseCallback), state);
     }
     catch (SecurityException)
     {
         this.CreateNonGifAnimationImage(true);
     }
 }
Пример #3
0
        private void WebReadCallback(IAsyncResult asyncResult)
        {
            WebReadState asyncState = (WebReadState)asyncResult.AsyncState;
            int          count      = asyncState.readStream.EndRead(asyncResult);

            if (count > 0)
            {
                asyncState.memoryStream.Write(asyncState.buffer, 0, count);
                try
                {
                    asyncState.readStream.BeginRead(asyncState.buffer, 0, asyncState.buffer.Length, new AsyncCallback(this.WebReadCallback), asyncState);
                }
                catch (WebException exception)
                {
                    base.Dispatcher.Invoke(DispatcherPriority.Render, new WebRequestErrorDelegate(this.WebRequestError), exception);
                }
            }
            else
            {
                base.Dispatcher.Invoke(DispatcherPriority.Render, new WebRequestFinishedDelegate(this.WebRequestFinished), asyncState.memoryStream);
            }
        }