Exemplo n.º 1
0
 private void GetGifStreamFromHttp(Uri uri)
 {
     try
     {
         WebReadState webReadState = new WebReadState();
         webReadState.memoryStream       = new MemoryStream();
         webReadState.webRequest         = WebRequest.Create(uri);
         webReadState.webRequest.Timeout = 10000;
         webReadState.webRequest.BeginGetResponse(new AsyncCallback(this.WebResponseCallback), webReadState);
     }
     catch (SecurityException ex)
     {
         this.CreateNonGifAnimationImage();
     }
 }
Exemplo n.º 2
0
        private void WebResponseCallback(IAsyncResult asyncResult)
        {
            WebReadState webReadState = (WebReadState)asyncResult.AsyncState;

            try
            {
                WebResponse response = webReadState.webRequest.EndGetResponse(asyncResult);
                webReadState.readStream = response.GetResponseStream();
                webReadState.buffer     = new byte[100000];
                webReadState.readStream.BeginRead(webReadState.buffer, 0, webReadState.buffer.Length, new AsyncCallback(this.WebReadCallback), webReadState);
            }
            catch (WebException ex)
            {
                this.Dispatcher.Invoke(DispatcherPriority.Render, (Delegate) new GifImage.WebRequestErrorDelegate(this.WebRequestError), ex);
            }
        }
Exemplo n.º 3
0
        private void WebReadCallback(IAsyncResult asyncResult)
        {
            WebReadState webReadState = (WebReadState)asyncResult.AsyncState;
            int          count        = webReadState.readStream.EndRead(asyncResult);

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