c# - For some reason my async method doesn't work in specific cases -


so... month ago started developing universal windows platform on visual studio, , made small app keep prices of bitcoin, ethereum , litecoin (each 1 chart , everything).

my problem comes in function called "gethisto", gets historic values last hour/day/week/month/year, , works expected changing between time-ranges clicking in 1 of 5 buttons, except if jump month/year last hour, when app stays loading forever.

this code gethisto:

    async internal static task gethisto(string crypto, string time, int limit) {         string url = "https://min-api.cryptocompare.com/data/histo" + time + "?e=cccagg&fsym="             + crypto + "&tsym=" + coin + "&limit=" + limit;          if (limit == 0)             url = "https://min-api.cryptocompare.com/data/histoday?e=cccagg&fsym=" + crypto + "&tsym=" + coin + "&alldata=true";          uri requesturi = new uri(url);         httpclient httpclient = new httpclient();         string response = "";           try {             //send request             response = await httpclient.getstringasync(requesturi);             var data = jtoken.parse(response);              //var jsonstatham = await getjsonasync(requesturi);             //jtoken data = jsonstatham.result;              //simplified code part not important 

the 2 lines comments on code method saw on http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html , although method app never crashes anymore, ui becomes none responsive while gets data, big drawback. (specially since added small loading animation, shows code, not method commented lines.

is there way i'm not aware of use 2 commented lines, while still leaving ui responsive?

edit: tried putting await on catch clause, still looks doesn't fire. when i'm debugging, , app going stuck, gets first line:

httpresponse = await httpclient.getasync(uri); 

and stays in line forever without going next 1 check status code:

httpresponse.ensuresuccessstatuscode(); 

edit2: okey, think know whats wrong! , it's not code, because created new project made same request in order automatically , went okey. "step back", , thought if problem when changed month/year hour, not day hour, time-span of different, , making test telerikui library i'm using charts, looks problem indeed how handle updating process of chart. how handle right now:

             case "hour":                 btc_datetimeaxis.labelformat = "{0:hh:mm}";                 btc_datetimeaxis.majorstepunit = telerik.charting.timeinterval.minute;                 btc_datetimeaxis.majorstep = 10;                 btc_datetimeaxis.minimum = datetime.now.addhours(-1);                 timespan = "hour";                 limit = 60;                 break;              case "day":                 btc_datetimeaxis.labelformat = "{0:hh:mm}";                 btc_datetimeaxis.majorstepunit = telerik.charting.timeinterval.hour;                 btc_datetimeaxis.minimum = datetime.now.adddays(-1);                 btc_datetimeaxis.majorstep = 6;                 timespan = "day";                 limit = 1500;                 break;              ..... 

so, whenever have chart on week/month/year mode, , jump directly hour, seems changing majorstepunit , majorstep values of axis breaks chart , whole app. (and guess debugger staying indefinitely on httpclient.getasync(uri); because of being various threads working not because line 1 causing bug.)


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -