-
Scripting a Progress Bar only works if total time is < 5 Seconds
Hi
I am trying to write a simple progress bar script, to use in my other scripts.// Function to update the progress bar
function updateProgressBar(value, max) {
var progressBarWindow = new Window("palette", "Progress", undefined);
var progressBar = progressBarWindow.add("progressbar", undefined, 0, max);
progressBarWindow.show();
progressBarWindow.center();
// Function to update the progress value
progressBarWindow.updateProgress = function (value) {
progressBar.value = value;
this.update();
};
return progressBarWindow;
}
// Example usage:
var progressBar = updateProgressBar(0, 100); // Create a progress bar with a maximum value of 100
var startTime = new Date().getTime(); // Get the current time
var duration = 5000; // 5 seconds in milliseconds
while (new Date().getTime() - startTime < duration) {
// Update the progress bar value based on the elapsed time
var elapsed = new Date().getTime() - startTime;
var progress = (elapsed / duration) * 100;
progressBar.updateProgress(progress);
}
// Close the progress bar window when done
progressBar.close();
this works totally fine for
var duration = 5000
for
var duration = 6000
it hangs and the progress bar doesn’t close, and is not closeable by hand afterwards.The same behavior happend when i tried to use in a script which looks in a bunch of layers. if the total time the script needs is under 5 seconds everything works fine, if it needs longer it hangs.
any ideas on that really strange behavior?