What happens if you call dispatcherOperation.Wait()
on an operation that has already completed? Also, the docs say that it returns a DispatcherOperationStatus
, but wouldn't that always be Completed
since it (supposedly) doesn't return until it's done?
I was trying to use it like this:
private void Update()
{
while (ops.Count > 0) ops.Dequeue().Wait();
}
public void Add(T item)
{
lock (sync)
{
if (dispatcher.CheckAccess())
{
list.Add(item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
}
else
{
ops.Enqueue(dispatcher.BeginInvoke(new Action<T>(Add), item));
}
}
}
I'm using this in WPF, so all the Add
operations have to occur on the UI thread, but I figured I could basically just queue them up without having to wait for it to switch threads, and then just call Update()
before any read operations to ensure that the list is up to date, but my program started hanging.