0

私はワーカースレッド(つまり、スレッドプールタスク)にいます...

私は私がするだろう電話を窓にかけます:

    Deployment.Current.Dispatcher.BeginInvoke(
      delegate () 
      {
        // Do something on ui thread...
      }
    );

Windowsストアアプリでこれを行うにはどうすればよいですか?

msdnを検索しましたが、空になりました...

ありがとう

4

1 に答える 1

0

答えは次のとおりです。

class ThreadUtility
{
  // Warning: "Because this call is not awaited, execution of the current method 
  // continues before the call is completed. Consider applying the 'await' 
  // operator to the result of the call."
  // But that's what we want here --- just to schedule it and carry on.
  #pragma warning disable 4014 
  public static void runOnUiThread(Windows.UI.Core.DispatchedHandler del)
  {
    CoreWindow window = CoreWindow.GetForCurrentThread();
    window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, del);
  }
  #pragma warning restore 4014
}

... 

    ThreadUtility.runOnUiThread(
      delegate () 
      {
        if(handler != null)
        {
          // Do something on ui thread...
        }
      }
    );
于 2012-11-23T06:07:46.567 に答える