[UWP]如何从BackgroundTask更新UI? UWP [英] [UWP]How do I update the UI from a BackgroundTask? UWP

查看:88
本文介绍了[UWP]如何从BackgroundTask更新UI? UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是总结的场景...


我有一个后台任务,我打算用它来更新Live Tile和可能的Toasts ......但是;我想依靠该后台任务来更新我的UI。


我有一个UWP(Windows 10通用Windows项目)构建的MVVM 我发现BackgroundTask实际上是与应用程序分开的;这是有道理的。然而;因此,我无法直接更新我的模型,因此最终通过ViewModel将
更新推送到UI。 我知道这是因为我已经测试了它,即使它们都在运行BackgroundTask更新一个不同的模型(因为它是一个完全独立的执行),而不是在运行的App中使用的相同模型。


理解这一点我决定尝试向App发送通知,因此依赖Notification来更新模型。 我似乎无法弄清楚这一点... 


所以...我需要做的是在运行BackgroundTask时更新我的​​UI(当应用程序运行时)。 有什么建议或答案吗?




爱,赞美,敬拜上帝:)

解决方案

 dispatcher.RunAsync 

https://msdn.microsoft.com/library/windows/apps/windows.ui.core.coredispatcher.runasync.aspx


Here's the summarized scenario...

I have a background task that I intend to use to update the Live Tile and possibly Toasts as well... However; I would like to rely on that background task to update my UI also.

I have a UWP (Windows 10 Universal Windows Project) built MVVM and I've discovered that the BackgroundTask is actually separate than the application; which makes sense. However; as a result I can't directly update my Model and therefore eventually push the update to the UI via a ViewModel.  I know this because I've tested it and even when they are both running the BackgroundTask updates a different Model (because it's a completely separate execution) than the same Model being used within the App running.

So understanding this I decided to try and push a notification to the App and therefore rely on the Notification to update the Model instead.  I can't seem to figure this out... 

So... what I need to do is update my UI (if and when the app is running) when the BackgroundTask is ran.  Any suggestions or answers?


Love, praise, and worship God :)

解决方案

dispatcher.RunAsync

https://msdn.microsoft.com/library/windows/apps/windows.ui.core.coredispatcher.runasync.aspx


这篇关于[UWP]如何从BackgroundTask更新UI? UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆