title: GetResponseAsync png link url - Parameter not valid
body: <p>I have to write a Windows Form application that print a png from url, I'd like to write the code asynchronously.
  Here is my <strong>working code</strong> (sync)</p>
  
  <pre><code>public Bitmap GetImage()
  {
      Bitmap bmp;
      var request = WebRequest.Create("http://www.basilicasanmarco.it/wp-content/themes/tema-basilicasmarco/library/images/patriarcato.png");
      using (var response = request.GetResponse())
      using (var stream = response.GetResponseStream())
      {
          bmp = new Bitmap(stream);
      }
      return bmp;
  }
  
  private void PrintImage(PaintEventArgs e)
  {
      using (var imag = GetImage())
      {
          if (imag == null)
              return;
          var newHeight = mainImage.Height;
          var rapporto = newHeight / (double) imag.Height;
          var newWidth = Convert.ToInt32(rapporto * imag.Width);
          var imageLocationX = Convert.ToInt32((mainImage.Width - newWidth) / 2.0);
          e.Graphics.DrawImage(imag, imageLocationX, 0, newWidth, newHeight);
      }
  }
  </code></pre>
  
  <p>Now I'd like to write the same code in a async await way, here is my snippet:</p>
  
  <pre><code>public async Task&lt;Bitmap&gt; GetImage()
  {
      Bitmap bmp;
      var request = WebRequest.Create("http://www.basilicasanmarco.it/wp-content/themes/tema-basilicasmarco/library/images/patriarcato.png");
      using (var response = await request.GetResponseAsync())
      using (var stream = response.GetResponseStream())
      {
          bmp = new Bitmap(stream);
      }
      return bmp;
  }
  
  private async Task PrintImageAsync(PaintEventArgs e)
  {
      using (var imag = await GetImage())
      {
          var newHeight = mainImage.Height;
          var rapporto = newHeight / (double) imag.Height;
          var newWidth = Convert.ToInt32(rapporto * imag.Width);
          var imageLocationX = Convert.ToInt32((mainImage.Width - newWidth) / 2.0);
          e.Graphics.DrawImage(imag, imageLocationX, 0, newWidth, newHeight);
      }
  }
  </code></pre>
  
  <p>The first synchronous code works well, when I turn to the async part I have the "Parameter not valid" exception (System.Drawing exception) in the</p>
  
  <pre><code>e.Graphics.DrawImage(imag, imageLocationX, 0, newWidth, newHeight);
  </code></pre>
  
  <p>code.
  The Bitmap obtained seems ok, it has the correct Width and Height but something is wrong inside it, only in the asynchronous method.</p>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>Update</strong>:
  I await the method in the <code>Paint</code> method of a <code>Panel</code> in the following way:</p>
  
  <pre><code>this.panel.Paint += new System.Windows.Forms.PaintEventHandler(this.mainImage_Paint);
  
  private async void mainImage_Paint(object sender, PaintEventArgs e)
  {
      await PrintImageAsync(e);
  }
  </code></pre>
  
  <p>What I want to obtain is to paint the downloaded image in a Panel instead that a PictureBox because I need a more low-level approach.</p>