locked
I need to show progress during some heavy computation

    Question

  • Can anyone please give me a clue as to how to do the following (in Javascript):-

    1. After a button click, hide the button and show a progress bar.
    2. Do some heavy numeric computation, updating the progress bar within the main loop.
    3. At finish, hide the progress bar and show the button again.

    I think that I've got in a complete knot with Promises! I know how to show/hide the buttons etc. but how do I get the UI to update?

    Wednesday, December 12, 2012 8:53 PM

Answers

  • It sounds like the "heavy" work you're doing is synchronous which isn't allowing the UI to update itself. Even if you wrap the work inside a promise, it is still performed synchronously its just wrapped with those completion handlers for you.

    What you really need to do is actually make the work asynchronous. If you provide some detail on what exactly you're trying to achieve we may be able to point you in the right direction for this, but here are a couple of options for making your work truly asynchronous (options stolen in part from StackOverflow):

    - WebWorkers: getting data in and out of a web work involves post/sendMessage.

    - If your operation is not JavaScript specific, you can create a thread in C#/C++ and use that to communicate back to the JavaScript world using WinRT events.

    • Proposed as answer by got.dibbs Thursday, December 13, 2012 2:55 PM
    • Marked as answer by Song Tian Tuesday, December 18, 2012 8:13 AM
    Wednesday, December 12, 2012 10:49 PM

All replies

  • It sounds like the "heavy" work you're doing is synchronous which isn't allowing the UI to update itself. Even if you wrap the work inside a promise, it is still performed synchronously its just wrapped with those completion handlers for you.

    What you really need to do is actually make the work asynchronous. If you provide some detail on what exactly you're trying to achieve we may be able to point you in the right direction for this, but here are a couple of options for making your work truly asynchronous (options stolen in part from StackOverflow):

    - WebWorkers: getting data in and out of a web work involves post/sendMessage.

    - If your operation is not JavaScript specific, you can create a thread in C#/C++ and use that to communicate back to the JavaScript world using WinRT events.

    • Proposed as answer by got.dibbs Thursday, December 13, 2012 2:55 PM
    • Marked as answer by Song Tian Tuesday, December 18, 2012 8:13 AM
    Wednesday, December 12, 2012 10:49 PM
  • Thank you very much. I think that's what I expected, but it's nice to have it confirmed!

    I will try the "C" route!

    Thursday, December 13, 2012 7:26 AM