title: Passing C# window handle to unmanaged code - Cross-thread exception
body: <p>I've run into an issue recently where attempting to implement a real-time video capture with a video capture library and capture card.  The unmanaged library is much faster at processing the data than I can manually, so it seems the way to go.  The unmanaged library is looking for a window handle for a control to update.</p>
  
  <p>The Platform Invoke for the source works fine on a one-off update and when I thread it with my own Invoke, so I know the types are all correct and that it's marshaling properly.  </p>
  
  <p>The main issue is that when I attempt to thread the operation and pass the window handle directly to unmanaged code, I get the dreaded "Cross-thread operation not valid" exception.</p>
  
  <p>I understand the problem, just not quite sure how to fix it.  So, how do I use a delegate and "BeginInvoke()" method on control when unmanaged code just needs the window handle?  Is it even possible to arrange this?</p>
  
  <p>Here's a snippet of the unmanaged library functionality:</p>
  
  <pre><code>class Video
      {
          [DllImport("video.dll", EntryPoint = "imagePlot", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
          private static extern int imagePlot(IntPtr windowHandle, byte[] imageBuffer);
  
          private PictureBox _control;
          public Video(PictureBox control)
          {
              _control = control;
          }
  
          public void CaptureAndUpdate()
          {
              // capture video
              byte[] video = Capture();
  
              // plot video
              imagePlot(_control.Handle, video);
          }
      }
  </code></pre>