CoreWindow :: GetCurrentForThread () is always NULL

I am trying to get CoreDispatcher in C ++ on Windows Phone 8 so that I can send work items to the UI thread manager so that I can update the user interface elements in the UI thread. However, when I call CoreWindow::GetCurrentForThread() , I get NULL back. The documentation says this is supported by WP8. While I get NULL for the current window, I cannot get the current Dispatcher from it; Does anyone know how to get the current WP8 dispatcher?

+4
windows-runtime windows-phone-8 c ++ - cx
Jan 24 '13 at 8:46
source share
2 answers

CoreWindow::GetForCurrentThread() documented as a return:

CoreWindow for the current active thread.

If you call this function from a thread that does not have CoreWindow (for example, any thread other than the UI), then this function will return nullptr .

Assuming the application has completed initialization, and there is a view, you can use the dispatcher from the main view of the application through CoreApplication::MainView , you can pass Dispatcher^ for the user interface thread to code that runs in a non-UI thread, so that he had access to it when he needed to return to the user interface thread.

+2
Jan 24 '13 at 16:04
source share

I used

 await CoreApplication.Views.First().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { //your code here }); 
0
Mar 05 '17 at 14:09
source share



All Articles