Class ThreadInterruptMonitor

Class ThreadInterruptMonitor

Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)

Simple implementation of Aspose.Cells.AbstractInterruptMonitor by starting another thread to require the interruption after sleeping user specified limit.

public class ThreadInterruptMonitor : AbstractInterruptMonitor

Inheritance

objectAbstractInterruptMonitorThreadInterruptMonitor

Inherited Members

AbstractInterruptMonitor.IsInterruptionRequested, AbstractInterruptMonitor.TerminateWithoutException, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

The following example shows how to monitor the load and save procedure with specified time limit:

csharp
[C#]

ThreadInterruptMonitor monitor = new ThreadInterruptMonitor(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 finishes the monitor thread and starts to monitor the save procedure
monitor.FinishMonitor();
monitor.StartMonitor(1500); //time limit is 1.5 seconds
wb.Save("result.xlsx");
monitor.FinishMonitor();

Remarks

One monitor instance can be used repeatedly, as long as you monitor each process in sequence. It should not be used to monitor multiple procedures concurrently in multi-threads.

Constructors

ThreadInterruptMonitor(bool)

Constructs one interruption monitor.

public ThreadInterruptMonitor(bool terminateWithoutException)

Parameters

terminateWithoutException bool

Aspose.Cells.AbstractInterruptMonitor.TerminateWithoutException

Properties

IsInterruptionRequested

This implementation just checks whether the time cost(from the time when starting this monitor to now) is greater than user specified limit.

public override bool IsInterruptionRequested { get; }

Property Value

bool

TerminateWithoutException

See Aspose.Cells.AbstractInterruptMonitor.TerminateWithoutException. This property is specified by user when constructing this monitor instance.

public override bool TerminateWithoutException { get; }

Property Value

bool

Methods

FinishMonitor()

Finishes the monitor for one procedure.

public void FinishMonitor()

Remarks

Calling this method after the monitored procedure can release the monitor thread earlier, especially when there is no interruption for it(the time cost of that procedure is less than the specified time limit).

StartMonitor(int)

Starts the monitor with the specified time limit. The start time to calculate time cost is just when this method is called, so the procedure which needs to be monitored should be started just after this call.

public void StartMonitor(int msLimit)

Parameters

msLimit int

time limit(ms) to require the interruption.