Skip to content

Instantly share code, notes, and snippets.

@luetm
Created April 12, 2016 15:26
Show Gist options
  • Save luetm/3d3c329f7c2b3d4e0fa6cff26c2cb3a2 to your computer and use it in GitHub Desktop.
Save luetm/3d3c329f7c2b3d4e0fa6cff26c2cb3a2 to your computer and use it in GitHub Desktop.
public ObservableCollection 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