我想使用 ppl 任务在后台做一些工作,并在完成后在窗口中显示结果。在我的例子中,UI 框架是 MFC。结构将是:
using namespace concurrency;
create_task([] {
// this can be run in any thread, shouldn't be the UI thread
// do real work here
return 42;
}).then([](int n)
{
// this should be run on the UI thread
// ... open a MFC window to display results
});
问题是,非 Windows 应用商店应用不允许指定 task_continuation_context。相反,运行时决定将使用哪个上下文(请参阅task_continuation_context 类)。我可以依靠运行时可靠地确定它需要在 UI 线程上运行延续吗?是否有合理的解决方法来实现我想要的 - 不阻塞 UI 线程?
更新:到处玩表明运行时不会在 UI 线程上运行延续。那么,这不可能吗?