When does a PPL task execute on the UI thread?

感情迁移 提交于 2020-01-16 04:14:08

问题


When calling create_task is there a way to ensure that the task doesn't run on the UI thread?

I want to be sure I'm not inadvertently calling wait inside a task that somehow managed to execute on the UI thread.


回答1:


The create_task function won't spontaneously jump onto the UI thread: if you don't call it from the UI thread it won't execute there. You need to explicitly call the Dispatcher to get back.

An apartment aware task (one which returns IAsyncAction or IAsyncOperation) will continue in its apartment by default if a task_continuation_context isn't provided to tell it otherwise. The common case of starting a task on a UI thread will continue on the UI thread.

See the Managing the thread context section of MSDN's Asynchronous programming in C++ docs for more details.



来源:https://stackoverflow.com/questions/30134704/when-does-a-ppl-task-execute-on-the-ui-thread

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