Skip to content

Instantly share code, notes, and snippets.

@luetm
Created April 12, 2016 15:24
Show Gist options
  • Save luetm/137374dd47ee247c9a7bd92f69364d51 to your computer and use it in GitHub Desktop.
Save luetm/137374dd47ee247c9a7bd92f69364d51 to your computer and use it in GitHub Desktop.
public ObservableCollection<IInvoicePosition> Positions // << dependency property
{
get { /* ... */ }
set { /* ... */ }
}
private volatile int _queue;
private readonly object _queueLock = new object();
private async void OnItemsSourceChanged(object sender, NotifyCollectionChangedEventArgs e)
{
lock (_queueLock)
{
_queue++;
}
// I use a await instead of Thread.Sleep() to avoid blocking the UI thread
// This might be the crux, any better way?
await Task.Delay(100);
lock (_queueLock)
{
_queue--;
}
if (_queue > 0) return;
Draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment