c# 4.0 - Metro App UI ProgressRing does not update and UI hangs -


i have button named bexecute , it's click event handler has body:

try {     // activate progress ring     prprogress.visibility = visibility.visible;     prprogress.isactive = true;     bexecute.isenabled = false;      // task     dotask(); } catch(exception ex) {     // } {     // stop progress ring     prprogress.visibility = visibility.collapsed;     prprogress.isactive = false;     bexecute.isenabled = true; } 

this method has these problems:

  • the ui appears hang until task completed , resumes per normal.
  • progressring never appears activated.
  • the bexecute button never appears enabled/disabled.

i can wrap doexecute() in task.run() method, frees ui, never see progressring , nor see bexecute being enabled/disabled.

any suggestions?

i guess dotask() cpu intensive method taking long time complete. way you're doing now, executes on ui thread , blocks. should wrap in task.run() call suggested, need await it, otherwise rest of event handler executed before task completes.

try rewriting event handler this:

private async void bexecute_onclick(object sender, routedeventargs e) {     try     {         // activate progress ring         prprogress.visibility = visibility.visible;         prprogress.isactive = true;         bexecute.isenabled = false;          // task         await task.run(() => dotask());     }     catch(exception ex)     {         //     }         {         // stop progress ring         prprogress.visibility = visibility.collapsed;         prprogress.isactive = false;         bexecute.isenabled = true;     } } 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -