Answer the question
In order to leave comments, you need to log in
Why does the application crash on the second call to DownloadStringTaskAsync?
Hello. The application is thrown into an UnhandledException on the second call to this function.
public static class Locator
{
public static async Task<List<Location>> GetCitiesAsync(string token = "", int max = 5)
{
WebClient wc = new WebClient();
string resultContent = await wc.DownloadStringTaskAsync(new Uri(string.Format("http://www.site.ru/ajax/geo.cshtml?_=r&context=&token={0}&max_matches={1}&use_similar=0", HttpUtility.UrlEncode(token), max.ToString())));
// parse ...
Locations ll = JsonConvert.DeserializeObject<Locations>(resultContent);
return (from l in ll.locations select l).Take(max).ToList();
}
}
async void LocationsFunc(string search)
{
if (IsLoading)
return;
IsLoading = true;
List<Location> locs = await Locator.GetCitiesAsync(search);
IsLoading = false;
}
A first chance exception of type 'System.Exception' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
A first chance exception of type 'MS.Internal.WrappedException' occurred in System.Windows.dll
Answer the question
In order to leave comments, you need to log in
And even that doesn't work?
if (IsLoading)
return;
try {
IsLoading = true;
List<Location> locs = await Locator.GetCitiesAsync(search);
} catch (Exception ex) {
Debug.Break();
// тут бы MessageBox какой-нибудь или записать в лог
} finally {
IsLoading = false;
}
It's very strange, but now the code from my initial post is working.. yesterday I fixed it by replacing the line
List locs = await Locator.GetCitiesAsync(search);
on
foreach (Location loc in await Locator.GetCitiesAsync(search))
...
and it worked. Apparently the whole point was to bind the Task to some local variable. try/catch wrapped everything and everything, but nothing was caught, but just fell .. I didn’t try to restart the emulator, maybe it was somewhere in the depths of the system ..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question