【问题标题】:How can i update the UI of my Windows universal app from a seperate thread?如何从单独的线程更新我的 Windows 通用应用程序的 UI?
【发布时间】:2016-07-27 15:52:37
【问题描述】:

我有一个使用 C# 和 XAML 在 Windows 8 手机上的警报应用程序。当我在应用程序运行时收到通知时,我能够使用此代码更新 UI。

   private void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
    {
        Dispatcher.BeginInvoke(async () =>
        {
           Textboc.text = "Something";
        });
    }

但是,我现在已将我的应用程序移至 Windows 10 Universal。 Dispatcher.BeginInvoke 似乎不可用。有没有其他方法可以用来更新 UI?

【问题讨论】:

    标签: c# multithreading xaml windows-10-universal


    【解决方案1】:
    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
            CoreDispatcherPriority.Normal,
            () => { // your code should be here});
    

    Correct way to get the CoreDispatcher in a Windows Store app

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多