BillyRayPreachersSon
Programmer
Hi all...
I'm writing some recursive code that parses a tree structure (of some 7000 - 10000 nodes), which takes about 15 - 20 seconds to complete.
I would like some sort of progess indicator to let the user know how the operation is progressing. At present, I have a DIV on the page, and every so often (maybe every 100 - 500 nodes) set the contents of the DIV using:
My problem is that Javascript doesn't appear to be very instant with the screen updating, and doesn't display anything until the entire tree has been parsed (presumably because it is still within a tight loop at 100% CPU utilisation).
While I could use setTimeout to pause momentarily after writing to the screen, over 10000 nodes, these delays every 100 nodes or so would add a considerable amount of time to the total time taken to parse the tree. I would also have to extensively modify my recursion code to be able to stop, and carry on at the same point it left off - something which I'd rather not do if I can avoid it.
So my question: Does anyone know of a way to force the browser to update the screen? Or maybe a better way of creating some sort of progress indicator that works well within a tight loop, but without slowing down the execution of code by too much.
Thanks in advance!
Dan
I'm writing some recursive code that parses a tree structure (of some 7000 - 10000 nodes), which takes about 15 - 20 seconds to complete.
I would like some sort of progess indicator to let the user know how the operation is progressing. At present, I have a DIV on the page, and every so often (maybe every 100 - 500 nodes) set the contents of the DIV using:
Code:
document.getElementById('myDivId').innerHTML = 'Node count: ' + myNodeCount;
My problem is that Javascript doesn't appear to be very instant with the screen updating, and doesn't display anything until the entire tree has been parsed (presumably because it is still within a tight loop at 100% CPU utilisation).
While I could use setTimeout to pause momentarily after writing to the screen, over 10000 nodes, these delays every 100 nodes or so would add a considerable amount of time to the total time taken to parse the tree. I would also have to extensively modify my recursion code to be able to stop, and carry on at the same point it left off - something which I'd rather not do if I can avoid it.
So my question: Does anyone know of a way to force the browser to update the screen? Or maybe a better way of creating some sort of progress indicator that works well within a tight loop, but without slowing down the execution of code by too much.
Thanks in advance!
Dan