Monitorare programmi in esecuzione con Node.js via C++
Come monitorare un programma in esecuzione
Il seguente esempio di codice mostra come monitorare un programma in esecuzione. Questo codice può essere utilizzato per monitorare l’esecuzione di codice relativo a Workbook. Usa semplicemente la classe SystemTimeInterruptMonitor per creare un oggetto di monitoraggio, utilizza la funzione LoadOptions.setInterruptMonitor(AbstractInterruptMonitor) per aggiungerlo ai parametri di caricamento di LoadOptions, e poi usa la funzione startMonitor per impostare il tempo di interruzione previsto (in millisecondi). Se il tempo di esecuzione del codice monitorato supera il tempo previsto, il programma verrà interrotto e verrà sollevata un’eccezione.
Codice di Esempio
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");