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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -