Forum for the PDF-XChange Editor - Free and Licensed Versions
Moderators:PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
When using the new app.setInterval with a function parameter that encloses app.clearInterval, the application will crash after the interval is cleared.
{
let intervalTimer = new Date();
// test built-in interval function
let interval = app.setInterval( function testInterval() {
let stopTimer = (new Date() - intervalTimer) > 5 * 1000;
if (stopTimer) {
app.clearInterval(interval);
if ( 4 === app.alert({cMsg:"Do you need more time?", nIcon: 2, nType: 2})) {
intervalTimer = new Date();
// restart
interval = app.setInterval( testInterval, 500);
}
}
console.println('click...' + Math.ceil(10 - (new Date() - intervalTimer)/500));
}, 500);
}
The application (builds 393 and 394) crashes every time I press "Cancel".
Workaround
My current workaround is a recursive setTimeOut.
Thank you for the report, I have reproduced this in build 395 as well, and passed it along to the Dev team for review.
Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
async function doIntervalWork() {
for await (const i of new AsyncIntervalGenerator(500)) {
if ((i + 1) % 10 == 0) {
if ( 4 !== app.alert({cMsg:"Do you need more time?", nIcon: 2, nType: 2}))
break;
}
console.println(`${i + 1} bits of work`);
}
return 'Done';
}
doIntervalWork().then((status) => console.println(`Finished with status '${status}'`));
console.println('Started');
Or, if you want to completely separate the interval management logic from the actual payload, you can split the doIntervalWork function like this:
async function* workIntervals() {
for await (const i of new AsyncIntervalGenerator(500)) {
if ((i + 1) % 10 == 0) {
if ( 4 !== app.alert({cMsg:"Do you need more time?", nIcon: 2, nType: 2}))
break;
}
yield i;
}
}
async function doIntervalWork() {
for await (const i of workIntervals()) {
console.println(`${i + 1} bits of work`);
}
}