Itβs hard to say what the problem is. I would like to see the output if you put the print string in setProgress to print the timestamp. Does he really shoot every tenth of a second? I guess that is not the case.
Why not? Well, a timer plans to execute a loop in the main thread to execute code in setProgress. This task cannot be performed until tasks in front of it in the queue are completed. Therefore, if long tasks are performed in your main thread, your timer will work very inaccurately. My first suggestion is that this is possibly what is happening.
Here is an example:
- You start a timer to do something every second.
- Immediately after that, you start working with a large number of tasks of the main stream (for example, you are trying to write a ton of data to a file). This task will take five seconds.
- Your timer wants to start after one second, but your write to the file clogging the main stream for the next four seconds, so the timer cannot be triggered for another four seconds.
If this is the case, then to solve the problem you will need to either move this main thread to the background thread, or figure out how to execute it, periodically returning to the start loop. For example, during a lengthy main thread operation, you can periodically call runUntilDate in a run loop to perform other tasks in the run loop.
Please note that you could not simply increase the number of progress indicators during the long execution of the main thread task, because the progress indicator does not actually activate its filling until you return to the execution cycle.
Aurast
source share