実行中のプログラムの監視

実行中のプログラムの監視方法

次のサンプルコードは、実行中のプログラムを監視する方法を示しています。このコードは、Workbook に関連するコードの実行を監視するために使用できます。単純に SystemTimeInterruptMonitor クラスを使用して監視オブジェクトを作成し、LoadOptions の実行パラメータに追加するために SetInterruptMonitor 関数を使用し、その後 StartMonitor 関数を使用して期待される中断時刻(ミリ秒単位)を設定します。監視されているコードの実行時間が期待される時間を超過すると、プログラムが中断されて例外がスローされます。

サンプルコード

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();