I'm developing a UWP application, which uses SignalR to send realtime messages to an API.
Everything works fine, even if my app enters the suspended state (for example user goes to lock screen), signalr succeed in keeping connections alive.
Problem is, when the internet connection is lost while app is suspended, web socket connection goes down and I'd like to reopen the connection as soon as internet access is up again.
But I can't manage making this works, calling:
await HubConnection.Start();
hangs indefinitely, it never returns and connection does not restart. I've investigated a little, and it seems IHubConnection.Start() calls a new thread, which is queued because app is suspended. The same way I tried to call the dispatcher like this:
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
async () =>
{
await HubConnection.Start(); // 1
});
The statement // 1 is never called during suspended state, but as soon as the app is resumed, it is executed.
Is it possible to restart the SignalR connection while app is suspended? Or does it need a new thread which has to be queued until app resumes?