Monitor running programs
How to monitor a running program
The following sample code shows how to monitor a running program. This code can be used to monitor the running of Workbook related code. Simply use the SystemTimeInterruptMonitor class to create a monitoring object, use the SetInterruptMonitor function to add it to the LoadOptions running parameters, and then use the StartMonitor function to set the expected interruption time (in milliseconds). If the running time of the monitored code exceeds the expected time, the program will be interrupted and an exception will be thrown.
Sample Code
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"); |