My application retrieves data from server by asynchronous calls to apis. It works fine as long as the user remains in app. After implementing Fast App Resume, when app resumes after clicking on the tile, the control comes to the page on which user left previously.
If there was any asynchronous call running when user had deactivated the app(hit the start button previously), it throws the following exception..
In fact this exception is thrown by the following code.
private async Task<string> httpRequest(HttpWebRequest request)
{
string received;
using (var response = (HttpWebResponse)(await Task<WebResponse>.Factory
.FromAsync(request.BeginGetResponse, request.EndGetResponse, null)))
{
using (var responseStream = response.GetResponseStream())
{
using (var sr = new StreamReader(responseStream))
{
//cookieJar = request.CookieContainer;
//responseCookies = response.Cookies;
received = await sr.ReadToEndAsync();
}
}
}
return received.Replace("[{}]", "[]")
.Replace("[{},{}]", "[]")
.Replace("\"subcat_id\":\"\"", "\"subcat_id\":\"0\"");
}
Is there any way to stop execution of the async method on OnNavigatedFrom method when user deactivates the app? Or is there any way to preserve the state of async call and resume it again?
Thanks in advance.