0

我在一个工作线程中(我的意思是,线程池任务)......

我的 windows phone 我会做:

    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 回答