【发布时间】:2013-07-21 23:12:20
【问题描述】:
我正在阅读 MS 提供的示例 Hilo,在 ImageBrowserViewModel.cpp 下有一些我不明白的代码:
// Observe the update after waiting the specified amount of time.
create_task([timeToWait]() {
assert(IsBackgroundThread());
::wait(timeToWait);
}).then([weakThis]() {
assert(IsMainThread());
auto vm = weakThis.Resolve<ImageBrowserViewModel>();
if (nullptr != vm)
{
vm->ObserveFileChange();
vm->m_hasFileUpdateTask = false;
}
}, task_continuation_context::use_current()).then(ObserveException<void>(m_exceptionPolicy));
任务是应用程序使用IsBackgroundThread() 和IsMainThread() 断言它应该在特定上下文中正确调用。但是对于::wait(timeToWait) 函数调用,没有定义task_continuation_context 以确保它在后台运行,我只是想知道它是如何工作的?非常感谢!
【问题讨论】:
标签: multithreading windows-8 microsoft-metro windows-store-apps c++-cx