microsoft / Windows-task-snippets

Reusable code snippets for the Universal Windows Platform.
MIT License
307 stars 66 forks source link

what the difference between the other way to update the UI thread from a background thread #3

Closed lindexi closed 7 years ago

lindexi commented 8 years ago

I want to know what the difference between

  await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
      CoreDispatcherPriority.Normal,()=>
      {
           //Up date
     });

and

   await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.High,
           () =>
           {
               //Up date 
           });
KarlErickson commented 7 years ago

See CoreDispatcherPriority in the docs for info on this.

oldnewthing commented 7 years ago

Also, one dispatches to the main view, whereas the other dispatches to the current window.

KarlErickson commented 7 years ago

Thanks - I didn't see that part.

lindexi commented 7 years ago

Ths.If have no the current window as run in app.xaml.cs when the app running ,both will say null ref.And if it run in http await methor,the second will find the current is null.