I used electron Vue3 Vite Element-plus to create an application to process some txt files with 864000 lines. The processing method of the files is line by line, and the number of loops for each file will be greater than 864000 times. To this end, in order to ensure the timely display of the processing progress, I use a sleep function:
function sleep(milliseconds:number){
return new Promise((resolve) => {
setTimeout(resolve, milliseconds);
});
}
Andused each time the progress is changed:
await sleep(50);
The program runs smoothly when it is observable in the foreground, but when I occlude my program with another interface or minimize it, sleep(50) pauses for 1 second, and then slows down until it's completely run out pause. When the app gets focus again, the speed resumes.