c# - Repeat async task by timer in xamarin forms -


i'm new xamarin.forms development , i'm still having first steps few tutorials found on net. have async task returns time date.jsontest.com , have timer decrements text in label. want put async task in timer repeats , displays time on label im getting cannot convert async lamba func

here's code please me, thanks

static async task<string> requesttimeasync()     {         using (var client = new httpclient())         {             var jsonstring = await client.getstringasync("http://date.jsontest.com/");             var jsonobject = jobject.parse(jsonstring);             return jsonobject["time"].value<string>();         }     }    protected override async void onappearing()     {         base.onappearing();          timelabel.text = await requesttimeasync();          device.starttimer(timespan.fromseconds(1), () => { // want taks put  //here gets repeated             var number = float.parse(button.text) - 1;             button.text = number.tostring();             return number > 0;         });      } 

reloading content page in timer trick, if can please me appreciated

solved

as simple that

 private async void continuouswebrequest()     {         while (_keeppolling)         {             timelabel.text = "call: "+counter+" "+ await requesttimeasync()+environment.newline;             // update ui (because of async/await magic, still in ui thread!)             if (_keeppolling)             {                 await task.delay(timespan.fromseconds(5));             }         }     }      static async task<string> requesttimeasync()     {         using (var client = new httpclient())         {             var jsonstring = await client.getstringasync("http://date.jsontest.com/");             var jsonobject = jobject.parse(jsonstring);             timepage.counter++;             return jsonobject["time"].value<string>();         }      } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -