locked
How to call DispatchedHandler::Invoke()?

    Question

  • Its protected I know, but somehow the CoreDispatcher is able to call it in its runAsync method. How does it do that?
    Monday, May 13, 2013 3:31 PM

All replies

  • Hi,

    You can follow these codes

    		Windows::UI::Core::CoreDispatcher ^dispatcher = CoreWindow::GetForCurrentThread() -> Dispatcher;
    		dispatcher -> RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal,
    			ref new Windows::UI::Core::DispatchedHandler(
    			[]{
    			// change something in UI					);
    			}));
    

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 14, 2013 4:51 AM
  • Thanks Jesse for your answer. Thats not what I was asking though. I know how to use DispatchedHandler with the CoreDispatcher.

    I was interested in the internals of how it calls the DispatchedHandler::Invoke method because the crazy IntelliSense underlined my code when I wanted to call Invoke myself complaining that the call is protected. I needed that because in background tasks I do not have a CoreDispatcher available. However, the compiler did not complain (makes you wonder why IntelliSense uses a different set of rules than the compiler) but the app terminated when I called Invoke().

    Doesn't matter now anymore though, since I found out that just calling callbacks without DispatchedHandler works very well in background task scenarios.

    Tuesday, May 14, 2013 8:05 AM