我想在Background Task winmd上更新实时图块。
Public Async Sub Run(taskInstance As IBackgroundTaskInstance) Implements IBackgroundTask.Run
Dim deferral As BackgroundTaskDeferral = taskInstance.GetDeferral()
UpdateLiveTile()
deferral.Complete()
End Sub
'and
Public Shared Async Sub UpdateLiveTile()
....
await UpdateTileImage...something
End Sub
如果我制作这样的代码,后台任务会在UpdateTileImage
之前退出流程。
这意味着在完成整个过程之前已达到deferral.Complete()
。
因此,我尝试将UpdateLiveTile更改为Async Task,如:
Public Async Sub Run(taskInstance As IBackgroundTaskInstance) Implements IBackgroundTask.Run
Dim deferral As BackgroundTaskDeferral = taskInstance.GetDeferral()
Await UpdateLiveTile()
deferral.Complete()
End Sub
' and
Public Shared Async Function UpdateLiveTile() as Task
....
End Function
但编译器会抛出类似"更改方法签名以使用....."之类的错误。这可能告诉我无法在Windows运行时将该函数作为任务激活,而不是在正常的.Net框架中。
实际错误消息:Method' BackgroundTasks.NS.UpdateLiveTile()' 有一个参数类型为System.Threading.Tasks.Task'在它的 签名。虽然此类型不是有效的Windows运行时类型,但它 实现有效Windows运行时类型的接口。考虑 更改方法签名以使用以下类型之一 相反:''。 BackgroundTasks
总之,我只想确保在调用deferral.Complete()之前完成整个过程。谢谢!