【问题标题】:UWP (Windows 10) Background Task - Error HRESULT E_FAIL has been returned from a call to a COM component (VS2017)UWP(Windows 10)后台任务 - 错误 HRESULT E_FAIL 已从对 COM 组件的调用中返回(VS2017)
【发布时间】:2018-03-17 09:28:31
【问题描述】:

我有一个旨在用作 SignalR 客户端的 UWP Windows 10 应用。我以前有这个工作,但最近开始出现这个错误:Error HRESULT E_FAIL has been returned from a call to a COM component。不知道发生了什么变化,源代码控制中没有什么奇怪的。当我尝试通过ApplicationTrigger 触发后台任务时,它会出现。

这是我的 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 消息就好了。

【问题讨论】:

    标签: c# uwp signalr visual-studio-2017 template10


    【解决方案1】:

    问题是我在 Windows 10 隐私设置中禁用了此应用的后台任务。

    系统设置 => 隐私设置 => 后台应用

    我在后台任务注册期间发现了这一点,因为 BackgroundExecutionManager.RequestAccessAsync() 正在返回 BackgroundAccessStatus.DeniedBySystemPolicy

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 2023-03-15
      • 2016-12-12
      • 1970-01-01
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多