This class provides a means for early termination of graph algorithms.

Namespace: yWorks.yFiles.Algorithms
Assembly: yWorks.yFilesSilverlight.Algorithms (in yWorks.yFilesSilverlight.Algorithms.dll) Version: 2.4.0.0

Syntax

C#
public class AbortHandler
Visual Basic
Public Class AbortHandler

Remarks

This class provides a means for early termination of graph algorithms. Instances of this class may be attached to and retrieved from a graph and may receive requests for stopping and canceling an algorithm working on the graph.

Client Code Usage:
An instance of this class can be attached to a graph using method CreateForGraph(Graph) . Using the handler's Stop()()()() and Cancel()()()() methods, it is possible to schedule requests for early termination. Algorithms can check for these requests and handle them appropriately.

Stop()()()()
The algorithm should terminate gracefully, delivering a consistent result. Although the termination will be early, it usually will not be immediate.
Cancel()()()()
The algorithm should terminate immediately, all work done so far will be discarded.
IMPORTANT: It is not guaranteed that the processed graph will be in a consistent state after cancellation. For this reason it is strongly recommended to cancel only algorithms that work on copies of the real graph structure such as layout algorithms running in buffered mode. Furthermore, the state of the used ILayouter instance may become corrupted. Hence, a new instance has to be created after each cancellation.

If a graph with an attached handler is processed by multiple algorithms (or multiple times by one algorithm), the attached handler has to be Reset()()()() between algorithm runs. Otherwise, previous requests for early termination may lead to an undesired early termination of the next algorithm run.

Methods stop and cancel are primarily meant for multi-threaded use case scenarios where the algorithm runs in a background thread and stop/cancel are called from the main or UI thread. For pure single-threaded use cases, methods StopDuration and CancelDuration may be used to automatically stop or cancel the algorithm after a specified period of time has elapsed.

Usage in Algorithms:
Algorithms have to retrieve an instance of this class from the graph that is processed using method GetFromGraph(Graph) . The algorithm then needs to query the retrieved instance of this class for stop or cancel requests using method Check()()()() .
Alternatively, convenience method Check(Graph) for one-time checks is available. For performance critical code that checks repeatedly, it is recommended to follow the first approach, though.
When handling a stop request, algorithms should ensure that the resulting graph is still in a consistent state.

Inheritance Hierarchy

System..::..Object
  yWorks.yFiles.Algorithms..::..AbortHandler

See Also