protected virtual void OnDownloadToMemoryCompleted(DownloadToMemoryCompletedEventArgs e)
 {
     OnWorkFinished();
     if (DownloadToMemoryCompleted != null)
     {
         this.GetSyncContext()?.Post(new System.Threading.SendOrPostCallback(delegate { this.DownloadToMemoryCompleted.Invoke(this, e); }), null);
     }
 }
 private void InnerWebClient_DownloadToMemoryCompleted(object sender, DownloadToMemoryCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         if (e.Error is WebException)
         {
             WebException ex = e.Error as WebException;
             if (IsHTTP(this.LastURL))
             {
                 if (ex.Response is HttpWebResponse && WorthRetry(ex.Response as HttpWebResponse))
                 {
                     this.innerWebClient.DownloadToMemoryAsync(this.LastURL, lasttag, e.UserState);
                 }
                 else
                 {
                     this.OnDownloadToMemoryCompleted(e);
                 }
             }
             else
             {
                 this.OnDownloadToMemoryCompleted(e);
             }
         }
         else if (e.Error.InnerException is WebException)
         {
             WebException ex = e.Error.InnerException as WebException;
             if (IsHTTP(this.LastURL))
             {
                 if (ex.Response is HttpWebResponse && WorthRetry(ex.Response as HttpWebResponse))
                 {
                     this.innerWebClient.DownloadStringAsync(this.LastURL);
                 }
                 else
                 {
                     this.OnDownloadToMemoryCompleted(e);
                 }
             }
             else
             {
                 this.OnDownloadToMemoryCompleted(e);
             }
         }
     }
     else if (e.Cancelled)
     {
         this.OnDownloadToMemoryCompleted(e);
     }
     else
     {
         this.OnDownloadToMemoryCompleted(e);
     }
 }