Мониторинг запущенных программ с Node.js через C++
Как отслеживать работающую программу
Следующий пример показывает, как мониторить запущенную программу. Этот код можно использовать для отслеживания выполнения Workbook. Просто используйте класс SystemTimeInterruptMonitor для создания объекта мониторинга, вызовите функцию LoadOptions.setInterruptMonitor(AbstractInterruptMonitor), чтобы добавить его в параметры выполнения LoadOptions, и затем используйте функцию startMonitor, чтобы указать ожидаемое время прерывания (в миллисекундах). Если время выполнения мониторируемого кода превышает ожидаемое, программа будет прервана и возникнет исключение.
Образец кода
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Large.xlsx");
const monitor = new AsposeCells.SystemTimeInterruptMonitor(false);
const lopts = new AsposeCells.LoadOptions();
lopts.setInterruptMonitor(monitor);
monitor.startMonitor(1000); // time limit is 1 second
// Loads the workbook with the specified load options
const wb = new AsposeCells.Workbook(filePath, lopts);
// if the time cost of loading the template file exceeds one second, interruption will be required and exception will be thrown here
// otherwise starts to monitor the save procedure
monitor.startMonitor(1500); // time limit is 1.5 seconds
wb.save("result.xlsx");