1
我已经在Windows Phone的10从后台任务事件发送到UI
在我的后台任务实现的应用程序,而应用程序工作的一些工作,它要调用的主要项目,并更新UI实时。
是否有任何机制将事件从后台任务发送到用于更新UI的主项目?
我已经在Windows Phone的10从后台任务事件发送到UI
在我的后台任务实现的应用程序,而应用程序工作的一些工作,它要调用的主要项目,并更新UI实时。
是否有任何机制将事件从后台任务发送到用于更新UI的主项目?
//backTask
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
//update ui
UIAction.?Invoke();
});
是否有任何机制来从后台任务发送事件的主要项目更新UI?
您可以注册Completed
事件的后台任务,并更新Completed
事件的UI:
注册完整的事件:
var registration= taskBuilder.Register();
registration.Completed += Registration_Completed;
private async void Registration_Completed(BackgroundTaskRegistration sender, BackgroundTaskCompletedEventArgs args)
{
var settings = ApplicationData.Current.LocalSettings;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() =>
{
tbResult.Text=settings.Values["BackgroundResult"].ToString();
});
}
的XAML:
<StackPanel VerticalAlignment="Center">
<Button Name="btnRegister" Click="btnRegister_Click">
Click Me to register BT
</Button>
<TextBlock Name="tbResult">
Here will show the result
</TextBlock>
</StackPanel>
这里是完整的演示:BackgroundTaskSample。
CoreApplication.MainView.CoreWindow – lindexi