fork download
  1. using System;
  2. using System.Net;
  3. using System.Diagnostics;
  4. using System.IO;
  5.  
  6. namespace Test
  7. {
  8. public class ImageDown
  9. {
  10. public static void Main ()
  11. {
  12. Do ();
  13.  
  14. while (true) {
  15. }
  16. }
  17.  
  18. public static void Do ()
  19. {
  20. var url = "https://w...content-available-to-author-only...o.jp/intl/ja_ALL/images/logos/images_logo_lg.gif";
  21.  
  22. var req = (HttpWebRequest)WebRequest.Create (url);
  23.  
  24. req.BeginGetResponse (BeginReadCallBack, req);
  25. }
  26.  
  27. class State
  28. {
  29. public Stream ResponseStream;
  30. public MemoryStream MemoryStream = new MemoryStream ();
  31. public byte[] Buffer = new byte[1024];
  32. }
  33.  
  34. static void BeginReadCallBack (IAsyncResult ar)
  35. {
  36. var req = (HttpWebRequest)ar.AsyncState;
  37. var response = (HttpWebResponse)req.EndGetResponse (ar);
  38. var stream = response.GetResponseStream ();
  39. var state = new State{ ResponseStream = stream };
  40. stream.BeginRead (state.Buffer, 0, state.Buffer.Length, ReadCallback, state);
  41. }
  42.  
  43. static void ReadCallback (IAsyncResult ar)
  44. {
  45. var state = (State)ar.AsyncState;
  46.  
  47. int readSize = state.ResponseStream.EndRead (ar);
  48.  
  49. if (readSize > 0) {
  50. state.MemoryStream.Write (state.Buffer, 0, readSize);
  51. state.ResponseStream.BeginRead (state.Buffer, 0, state.Buffer.Length, ReadCallback, state);
  52. } else {
  53. byte[] result = state.MemoryStream.GetBuffer ();
  54. Debug.WriteLine ("Complete");
  55. }
  56. }
  57. }
  58. }
  59.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty