c# - Exception in ReverseGeocodeQuery -


i'm using reversegeocodequery retrieve addresses of many locations. problem i'm getting exceptiona result, following message:

exception hresult: 0x80041b57

having reversegeocodequery class reference in msdn, can see listed in possible error results symbolic code of eerrorindexfailure. however, doesn't give me more information error, , stacktrace null too.

my code folloing:

foreach (var ev in events) {     reversegeocodequery query = new reversegeocodequery();     query.geocoordinate = ev.location;     query.querycompleted += (s, e)=>     {         if (e.error != null)             return;          ev.city = e.result[0].information.address.city;     };     query.queryasync(); } 

why getting error, , how make work?

apparently, api little limited , not possible make multiple reversegeocodequery calls simultaneously.

in order make them one-by-one following async/await pattern, have implemented extension method:

public static task<t> executeasync<t>(this query<t> query) {     var tasksource = new taskcompletionsource<t>();      eventhandler<querycompletedeventargs<t>> handler = null;      handler = (s, e) =>     {         query.querycompleted -= handler;          if (e.cancelled)             tasksource.setcanceled();         else if (e.error != null)             tasksource.setexception(e.error);         else             tasksource.setresult(e.result);     };      query.querycompleted += handler;      query.queryasync();      return tasksource.task; } 

and, modified code execute query following way:

foreach (var ev in events) {     reversegeocodequery query = new reversegeocodequery();     query.geocoordinate = ev.location;     var result = await query.executeasync();     ev.city = result[0].information.address.city; } 

this way, call not made until previous has finished. downside of approach can take long if have many places.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -