我想用ppl任務在後臺執行一些工作,並在完成後在窗口中顯示結果。在我的情況下,UI框架是MFC。結構將是:PPL任務 - 用於桌面應用程序的UI線程中的延續
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 Class)。 我可以依賴運行時來可靠地發現它需要在UI線程上運行延續嗎?是否有一個合理的解決方法來實現我想要的 - 而不會阻塞UI線程?
更新:各地播放顯示,運行時將無法運行在UI線程上的延續。那麼,這是不可能的?