miguelmpn
miguelmpn

Reputation: 2037

BeginInvoke is locking UI

I'm developing one application that displays images from one sensor. For this I'm using BeginInvoke on the Main UI.

private void cameraCtrller_ImageProcessed(object sender, ImageProcessedEventArgs e)
{
    if (myDisplay.InvokeRequired)
    {
        myDisplay.BeginInvoke(
            new EventHandler<ImageProcessedEventArgs>(cameraCtrller_ImageProcessed),
            sender,
            e
        );
    }
    else
    {
        myDisplay.DrawImage(e.Image);
    }
}

The issue is that the images are coming fast and the UI after some time (sporadically) gets unresponsive. Sensor is always faster than the UI..

While the UI is unresponsive, if I set a breakpoint at the BeginInvoke it breaks, but it never reaches the DrawImage.

Having this, I tried to execute Application.DoEvents(); after the break in the BeginInvoke and it started reaching DrawImage, but it is not a good solution to leave this at each image received.

Any ideas of how to solve this? any possibility to discard images that the UI cannot present?

Upvotes: 2

Views: 262

Answers (0)

Related Questions