title: Perform screen-scape of Webbrowser control in thread
body: <p>I am using the technique shown in </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/4269800/webbrowser-control-in-a-new-thread/4271581#4271581">WebBrowser Control in a new thread</a></p>
  </blockquote>
  
  <p>Trying to get a screen-scrape of a webpage I have been able to get the following code to successfully work when the <code>WebBrowser</code> control is placed on a <code>WinForm</code>. However it fails by providing an arbitrary image of the desktop when run inside a thread.</p>
  
  <pre><code>Thread browserThread = new Thread(() =&gt;
  {
      WebBrowser br = new WebBrowser();
      br.DocumentCompleted += webBrowser1_DocumentCompleted;
      br.ProgressChanged += webBrowser1_ProgressChanged;
      br.ScriptErrorsSuppressed = true;
      br.Navigate(url);
      Application.Run();
  });
  browserThread.SetApartmentState(ApartmentState.STA);
  browserThread.Start();
  
  private Image TakeSnapShot(WebBrowser browser)
  {
      int width;
      int height;
  
      width = browser.ClientRectangle.Width;
      height = browser.ClientRectangle.Height;
  
      Bitmap image = new Bitmap(width, height);
  
      using (Graphics graphics = Graphics.FromImage(image))
      {
          Point p = new Point(0, 0);
          Point upperLeftSource = browser.PointToScreen(p);
          Point upperLeftDestination = new Point(0, 0);
  
          Size blockRegionSize = browser.ClientRectangle.Size;
          blockRegionSize.Width = blockRegionSize.Width - 15;
          blockRegionSize.Height = blockRegionSize.Height - 15;
          graphics.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize);
      }
  
      return image;
  }
  </code></pre>
  
  <p>This obviously happens because of the method <code>Graphics.CopyFromScreen()</code> but I am unaware of any other approach. Is there a way to resolve this issue that anyone could suggest? or is my only option to create a form, add the control, make it visible and then screen-scrape? For obvious reasons I'm hoping to avoid such an approach.</p>