DispatcherOperations.Wait()
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-05-09T00:30:52Z
Indexed on
2010/05/09
0:38 UTC
Read the original article
Hit count: 209
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.
© Stack Overflow or respective owner