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