none
Dispatcher.Invoke replacement? RRS feed

  • Question

  • I've just upgraded to Win8 RC and Visual Studio 11 RC. My code no longer compiles because of Dispatcher.Invoke no longer existing. Can anyone provide some insight into the replacement for this?

    At a high level, i'm using a timer to wait 2 seconds before displaying some text.

    Some code:

    _timer =

    ThreadPoolTimer.CreateTimer(newTimerElapsedHandler(OnTimer), newTimeSpan(0, 0, 2));

    private

    voidOnTimer(ThreadPoolTimert)

            {

                _timer.Cancel();

               

               

    //Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.Normal, ShowText, this, null);


                ShowText();

            }

    Friday, June 1, 2012 12:46 AM

Answers

  • You'd need to use Dispatcher.RunAsync instead of Invoke.  This is more like BeginInvoke - it doesn't block.

    If you must block until it's done, use Dispatcher.RunAsync(...).AsTask().Wait();


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Seb 360 Friday, June 1, 2012 1:51 AM
    Friday, June 1, 2012 1:27 AM
    Moderator

All replies

  • You'd need to use Dispatcher.RunAsync instead of Invoke.  This is more like BeginInvoke - it doesn't block.

    If you must block until it's done, use Dispatcher.RunAsync(...).AsTask().Wait();


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Seb 360 Friday, June 1, 2012 1:51 AM
    Friday, June 1, 2012 1:27 AM
    Moderator
  • Ah yes, of course. Thanks for the response.
    Friday, June 1, 2012 1:51 AM