监控运行中的程序
Contents
[
Hide
]
如何监控运行中的程序
以下示例代码显示了如何监控运行中的程序。此代码可用于监控与Workbook相关的代码运行。只需使用SystemTimeInterruptMonitor类创建一个监控对象,使用SetInterruptMonitor函数将其添加到LoadOptions运行参数,并使用StartMonitor函数设置预期的中断时间(毫秒)。如果监控代码的运行时间超过预期时间,程序将被中断,并引发异常。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Aspose::Cells::Startup(); | |
SystemTimeInterruptMonitor monitor(false); | |
LoadOptions lopts; | |
lopts.SetInterruptMonitor((AbstractInterruptMonitor*) & monitor); | |
monitor.StartMonitor(1000); //time limit is 1 second | |
Workbook wb(u"Large.xlsx", 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(u"result.xlsx"); | |
Aspose::Cells::Cleanup(); |