PDA

View Full Version : if I update the messagebox too quick..



aj3423
14 Aug 2009, 12:49 AM
w = new Ext.Window({
title: 'window',
layout: 'fit',
width: 300,
height: 300,
items: [],
buttons: [new Ext.Button({
text: 'load',
handler: function() {
Ext.MessageBox.progress('Please Wait', 'Loading...');
//setTimeout(function() { // method 2
// showMsg();
//}, 500);
showMsg(); // method 1
function showMsg() {
for (i = 0; i <= 1000; i++) {
Ext.MessageBox.updateProgress(i / 1000, '' + i);
}
}
}
})]
});
w.show();
like the code, there are 2 problem:
1 if I use method 2, the Messagebox won't be updated until variable i reach 1000.
2 if I use method 1, the Messagebox won't show until i reach 1000.

How is that happen?
Thanks.

14 Aug 2009, 1:42 AM
OK, you're updating the progress for every iteration of the loop. That is just retarded.

aj3423
14 Aug 2009, 2:50 AM
aha, do you mean it will make the loop become slower? but I dont care how slow it would be, I just need it to show the detailed progress...

14 Aug 2009, 3:08 AM
Yeah dude! Use a task like in the examples.

aj3423
16 Aug 2009, 5:37 PM
But why doesn't the progress bar refresh in the for loop,,,

Animal
16 Aug 2009, 11:02 PM
The screen doesn't get redrawn till the Javascript thread yields. So looping to 1000 is just a wasteful way of setting it to 1000.

aj3423
17 Aug 2009, 10:04 AM
Thanks! I use a
setTimeout(function() {
working thread
}, 0);

to yield it, and it works fine.:)