Reputation: 719
I noticed that when I press the Windows button while doing a network request, and then, press the back button to come back to the app, the process is killed (HttpRequestException is thrown). I know that this happens because the Operating Sytem closes all networking connections when the app goes to the dormant state.
How can I handle properly this scenario? I mean, if I catch the exception, I should retry the network operations. I read that I could use a bool property that is set in the activated event to retry operations, but I don't like this approach because is easy that it fails.
Upvotes: 2
Views: 430
Reputation: 2727
This article from 2012 gives a good overview of what happens to a WebClient instance when the app is suspended or tombstoned, and some solutions...
As HttpClient
is a newer API, which supports Async/Await, another suggestion would be to use one of the RetryOnFault patterns from the Consuming the Task-based Asynchronous Pattern page on MSDN.
Upvotes: 1
Reputation: 9857
Register to
PhoneApplicationService.Current.Closing
It will be fired when your app is closing. There you can handle stopping any processes you need to.
Upvotes: 0