private static void getData_DownloadWallpaperCompleted(object sender, System.Net.OpenReadCompletedEventArgs e, string link, ref int doneThread, int maxThread, ref int downloaded) { try { var bitmap = e.Result.ConvertToBitmap(); if (bitmap == null) { throw new Exception(); } bitmap.Dispose(); Interlocked.Increment(ref downloaded); } catch { PrintColoredTextOnce(@" Failed at: " + link); } finally { doneThread++; if (doneThread >= maxThread) { doneThread = 0; rsEvent.Set(); } } }
private static void getData_OpenReadCompleted_Thumb(object sender, System.Net.OpenReadCompletedEventArgs e, ref int processed, int max, string thumbUrl) { try { var bitmap = e.Result.ConvertToBitmap(); if (bitmap == null) { throw new Exception(); } bitmap.Dispose(); DataCapsule.ThumbDownloadedSuccessfull(); } catch { PrintColoredTextOnce(@" Failed at: " + thumbUrl); } finally { processed++; if (processed >= max) { rsEvent.Set(); } } }
private void Client_OpenReadCompleted(object sender, System.Net.OpenReadCompletedEventArgs e) { using (var sr = new StreamReader(e.Result)) { while (!sr.EndOfStream) { sb.Append(sr.ReadLine()); } } // throw new NotImplementedException(); }
private static void getData_OpenReadCompleted_ResList(object sender, System.Net.OpenReadCompletedEventArgs e, ref int downloaded, int max, PictureData info, DataCapsule d) { try { var s = e.Result.ConvertToString(); d.ResPageHTMLList.Add(s); DataCapsule.ResPageDownloadedSuccessfull(); } catch { PrintColoredTextOnce(@" Failed at: " + new Uri(info.PageUrl).Host); } finally { downloaded++; if (downloaded >= max) { rsEvent.Set(); } } }
protected virtual void OnOpenReadCompleted(System.Net.OpenReadCompletedEventArgs e) { }
/// <summary> /// Get请求 回调 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Client_OpenReadCompleted(object sender, System.Net.OpenReadCompletedEventArgs e) { Console.WriteLine(sender.ToString()); DoNext(); }
private void WebClient_OpenReadCompleted(object sender, System.Net.OpenReadCompletedEventArgs e) { if (Timeout != null) { Timeout.Stop(); } if (e.Error == null && !e.Cancelled) { System.IO.BinaryReader BinaryStreamReader = new System.IO.BinaryReader(e.Result); byte[] Bytes; Bytes = BinaryStreamReader.ReadBytes(System.Convert.ToInt32(BinaryStreamReader.BaseStream.Length)); if (Bytes != null) { var ContentType = WebClient.ResponseHeaders["Content-Type"]; System.Text.Encoding Encoding = null; if (ContentType != "") { string[] Parts = ContentType.Split('='); if (Parts.Length == 2) { try { Encoding = System.Text.Encoding.GetEncoding(Parts[1]); } catch (Exception ex) { } } } if (Encoding == null) { var Row = System.Text.Encoding.UTF8.GetString(Bytes, 0, Bytes.Length); if (Row != "") { try { int P1 = Row.IndexOf("charset=") + 1; if (P1 > 0) { if (Row[P1 + 7] == '"') { P1 += 9; } else { P1 += 8; } int P2 = Row.IndexOf("\"", P1); if (P2 > 0) { var EncodeStr = Row.Substring(P1 - 1, P2 - P1); try { Encoding = System.Text.Encoding.GetEncoding(EncodeStr); // http://msdn.microsoft.com/library/vstudio/system.text.encoding(v=vs.100).aspx } catch (Exception ex) { } } } } catch (Exception ex) { } } } if (Encoding != null) { HTML = Encoding.GetString(Bytes, 0, Bytes.Length); if (Execute != null && HTML != null) { Execute(HTML); } } } } if (Elapse != null) { Elapse(); } }