Windows Phone: how to tell when Deployment.Current.Dispatcher.BeginInvoke has completed?

懵懂的女人 提交于 2019-11-30 23:53:27

It's very easy ;)

// must be executed in background
foreach (Item item in Items)
{
    EventWaitHandle Wait = new AutoResetEvent(false);
    Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        _events.Add(_newItem);
        Wait.Set();
    });
    // wait while item is added on UI
    Wait.WaitOne();
}
// here all items are added

This approach you can use everywhere where you need synchronize background and UI thread execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!