2017-10-05 110 views
1

我有一個旨在用作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消息。

回答

1

問題是我在Windows 10隱私設置中禁用了此應用程序的後臺任務。

系統設置=>隱私設置=>後臺應用

我我的後臺任務在註冊過程中發現這是BackgroundExecutionManager.RequestAccessAsync()返航BackgroundAccessStatus.DeniedBySystemPolicy

相關問題