UWP(Windows 10)后台任务 - 错误HRESULT E_FAIL已从调用COM组件(VS2017)返回
问题描述:
我有一个旨在用作SignalR客户端的UWP Windows 10应用程序。我有这个工作之前,但最近开始得到这个错误:Error HRESULT E_FAIL has been returned from a call to a COM component
。不知道是什么改变了,没有什么奇怪的源代码管理。当我尝试通过ApplicationTrigger
触发后台任务时出现。UWP(Windows 10)后台任务 - 错误HRESULT E_FAIL已从调用COM组件(VS2017)返回
这里是我的app.xml中的代码:
private void SignalR()
{
_hubConnection = new HubConnection("http://localhost/hollerhub");
_hubConnection.Credentials = CredentialCache.DefaultCredentials;
_toast = _hubConnection.CreateHubProxy("toast");
_toast.On<string>("broadcastMessage", msg =>
{
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values["toastInfo"] = msg;
var appTrigger = new ApplicationTrigger();
appTrigger.RequestAsync().GetResults(); // <--- This is where the error is thrown
});
_hubConnection.Start();
}
后台任务在应用程序启动的注册,但ApplicationTrigger
失败之前没有达到我的后台任务的代码。它正在接收SignalR消息。
答
问题是我在Windows 10隐私设置中禁用了此应用程序的后台任务。
系统设置=>隐私设置=>后台应用
我我的后台任务在注册过程中发现这是BackgroundExecutionManager.RequestAccessAsync()
返航BackgroundAccessStatus.DeniedBySystemPolicy
。