代码之家  ›  专栏  ›  技术社区  ›  codeMonkey mr. onoffon

UWP(Windows 10)后台任务-调用COM组件时返回错误HRESULT E_FAIL(VS2017)

  •  3
  • codeMonkey mr. onoffon  · 技术社区  · 7 年前

    我有一个UWP Windows 10应用程序,打算用作信号器客户端。我以前就有过这样的工作,但最近开始出现这样的错误: Error HRESULT E_FAIL has been returned from a call to a COM component ApplicationTrigger .

    这是我应用程序中的代码。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(); 
    }
    

    后台任务在应用程序启动时注册,但 应用程序触发器 在失败之前未达到我的后台任务代码。它正在接收信号器消息。

    1 回复  |  直到 7 年前
        1
  •  2
  •   codeMonkey mr. onoffon    7 年前

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

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

    我在后台任务注册时发现了这一点 BackgroundExecutionManager.RequestAccessAsync() BackgroundAccessStatus.DeniedBySystemPolicy .

    推荐文章