title: Updating WPF UI with BeginInvoke for Highspeed camera
body: <p>I use <code>ConcurrentQueue&lt;Action&gt; FrameActions</code> where I add image frames that come from a high-speed camera - (60-90 FPS)</p>
  <p>The Action contains methods to update the WritableBitmap image in UI.</p>
  <p>For updating frames I use a separate thread which code is below</p>
  <pre><code>void FrameUIThread()
      {
  
          do
          {
              if (FrameActions.TryDequeue(out Action currentAction))
              {
                  Application.Current.Dispatcher?.BeginInvoke(DispatcherPriority.Loaded, currentAction);
              }
              else
              {
                  // DoEvents
                  Application.Current.Dispatcher?.Invoke(DispatcherPriority.Loaded, new Action(() =&gt; { }));
              }
          } while (true);
      }
  </code></pre>
  <p>There was a problem that sometimes WritableBitmap is updated and a new image comes in, but the rest of the application - (all the buttons, counters and stuff are completely blocked, I can't click anything).
  Found that using DoEvents - helps in this situation.
  But now the flow of images is not smooth, but interrupted and goes spurts in some moments of time.</p>
  <p>Is there any way to solve this problem?
  Or could there be a better solution?</p>