c# - Xamarin development. Tasks are completing to early. I need advice regarding threads -
i have method using enable user input time. have set once button pressed opens dialog. user can select time, once user selects time meant populate textview have found once dialog opens textview assigned default value of null. doesn't wait.
when have ran tests using toast messages can see underlying code work order messing me about.
currently have attempting implement await feature no avail.
i have attached code. or advice. reasonably new c# , xamarin way.
<<within on create>> starttimepickerbtn.click += async delegate { oncreatedialog().show(); starttimetv.text = (await updatetime()).tostring(); }; private void timepickercallback(object sender, timepickerdialog.timeseteventargs e) { hour = e.hourofday; minute = e.minute; } public async task<string> updatetime() { string time = string.format("{0}:{1}", hour, minute.tostring().padleft(2, '0')); return time; }
you not awaiting call updatetime
, instead calling .tostring()
on task
returned, instead of string
.
your event handler should do
starttimetv.text = (await updatetime()).tostring();
Comments
Post a Comment