title: WPF: How to call Dispatcher.BeginInvoke *only* when there is nothing on the queue to be called?
body: <p>I have an import file method in a WPF app that reads a file and inserts some records in a DB.</p>
  
  <p>This method runs in a <code>BackgroundWorker</code> object.
  I have a progress bar being updated inside a <code>Dispatcher.Invoke</code> call. If I run as is, it takes ~1 minute to import 200k records, if I just don't show any progress, it takes just 4 to 5 seconds! And if I use <code>Dispatcher.BeginInvoke</code> with <code>Background</code> priority, it takes the same 4 to 5 seconds, but the progress bar + a counter are being updated and takes ~1 minute. So, obviusly, the UI is the problem here.</p>
  
  <p>And the other problem is that I need to show a progress, so I was thinking if there is any way to use <code>Dispatcher.BeginInvoke</code> but first check if there is anything on the queue and if so, I just skip it, which would behave like: in the 1st second, 1% done, 2 secs later 50% done and in the 4th second 100% done).</p>
  
  <p>Any help on this?</p>
  
  <p>thanks!!!</p>