android - Display ProgressBar while waiting for operation to complete -
in mvvmcross app have android progressbar defined as:
<progressbar android:id="@+id/progressbar" style="?android:attr/progressbarstylelarge" android:layout_width="fill_parent" android:layout_height="wrap_content" android:progressdrawable="@drawable/circular_progress_bar" android:gravity="right" local:mvxbind="visibility visibility(isbusy)" /> in viewmodel, code executed when clicking button start operation like:
public void next() { isbusy = true; try { //the expensive operation var response = calltimeconsumingservice(); if (response.methodfailed) { _dialogservice.displayalert(this, response.message); return; } showviewmodel<shownextview>(); } catch (exception ex) { _dialogservice.displayalert(this, ex.message); } isbusy = false; } but progressbar not displayed unless remove last isbusy = false;, means displayed when next() method hass exited (not while waiting)
what can display progressbar while waiting , disable before navigating next page?
===edit====
ended doing this:
public void next() { async () => { isbusy = true; await dowork(); isbusy = false; }); } adding rest of code dowork await task
//the expensive operation var response = await calltimeconsumingservicereturningtask();
this happening because process of updating ui happening in same thread expensive operation. until operation completed, ui thread blocked , visual feedback never shown properly. solve this, need make calltimeconsumingservice() async call (making return task<t>) , await complete.
if have network calls in method, blocking methods have async counterparts awaitable already. if method involves heavy processing, should use taskcompletionsource or task.run.
Comments
Post a Comment