监控运行中的程序
Contents
[
Hide
]
如何监控运行中的程序
以下示例代码显示了如何监视正在运行的程序。该代码可用于监视与Workbook相关的代码运行。只需使用SystemTimeInterruptMonitor类创建一个监视对象,使用SetInterruptMonitor函数将其添加到LoadOptions的运行参数中,然后使用StartMonitor函数设置预期的中断时间(毫秒)。如果被监视代码的运行时间超过预期时间,程序将被中断并抛出异常。
示例代码
This file contains hidden or 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
SystemTimeInterruptMonitor monitor = new SystemTimeInterruptMonitor(false); | |
LoadOptions lopts = new LoadOptions(); | |
lopts.InterruptMonitor = monitor; | |
monitor.StartMonitor(1000); //time limit is 1 second | |
Workbook wb = new Workbook("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("result.xlsx"); |