Task, await with webcam
<p>I'm trying to write a simple app with webcam support. I'm using this library (I know that was a mistake but now I would have to change too much :( ) <a href="http://easywebcam.codeplex.com/" rel="nofollow">http://easywebcam.codeplex.com/</a> .</p>

<p>When I'm connected to camera my UI response is very slow, when I change required fps from camera it's a little better (I think my UI gets as much as the camera gives).</p>

<p>I tried to write a function that gets frames in a thread so my UI doesn't slow down.</p>

<pre><code>async void webcam_ImageCapturedAsync(object source, WebcamEventArgs e)
{
    _FrameImage.Source = await Helper.LoadBitmapAsync((System.Drawing.Bitmap)e.WebCamImage);
}

void webcam_ImageCaptured(object source, WebcamEventArgs e)
{
    _FrameImage.Source = Helper.LoadBitmap((System.Drawing.Bitmap)e.WebCamImage);
}
</code></pre>

<p>And </p>

<pre><code>public async static Task&lt;BitmapSource&gt; LoadBitmapAsync(System.Drawing.Bitmap source) 
{
    return await Task&lt;BitmapSource&gt;.Run(() =&gt;
        {
            ip = source.GetHbitmap();
            bs = System.Windows.Interop.Imaging.
                     CreateBitmapSourceFromHBitmap(
                         ip,
                         IntPtr.Zero, System.Windows.Int32Rect.Empty,
                         System.Windows.Media.Imaging.BitmapSizeOptions.
                             FromEmptyOptions());
            DeleteObject(ip);

            return bs;
        });

    }

public static BitmapSource LoadBitmap(System.Drawing.Bitmap source)
{
    ip = source.GetHbitmap();
    bs = System.Windows.Interop.Imaging.
            CreateBitmapSourceFromHBitmap(
                ip,
                IntPtr.Zero,
                System.Windows.Int32Rect.Empty,
                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

    DeleteObject(ip);

    return bs;
}
</code></pre>

<p>Async methods are written by me and they don't work, and the other ones are from library.</p>

<p>When I start the program with async methods my imagebox stays grey, in debbuger I can see that my program is jumping between return and await but have no idea why.</p>

<p>Or when i try something like this</p>

<pre><code>async void webcam_ImageCaptured(object source, WebcamEventArgs e)
{
    BitmapSource bs = await Task.Run&lt;BitmapSource&gt;(() =&gt;
        {
            return Helper.LoadBitmap((System.Drawing.Bitmap)e.WebCamImage);
        });
    _FrameImage.Source = bs;
}
</code></pre>

<p>I get <code>InvalidOperationException: The calling thread cannot access this object because a different thread owns it</code>.</p>
