Implementing asynchronous algorithms

Developer wanting to implement their own asyncronous algorithms derive the algorithm class from ILAsyncAlgorithm. The following steps are nesseccary for implementation.

  • create your algorithm as a new class which derives from ILNumerics.Algorithms.ILAsyncAlgorithm
  • implement your algorithm parameter as private user defined struct inside the class. That struct will be given to the worker thread as the only parameter.
  • implement a constructor, calling the base class constructor and receiving all the parameters you need
  • implement the abstract functions derived from the base class.

The following table lists all functions to be overwritten in your class. Some of them are abstract functions which need to be implemented.

functiontype definition from ... Purpose
constructor constructor --- create base class and this algorithm instance. Defines your parameter list.
object AlgorithmFunction(object parameter)abstract function defined in ILAsyncAlgorithmThe working function - does the main calculation of your algorithm. Input and output parameter can be arbitrary structs or objects of arbitrary type. Here your algorithm spends its time. Here you should also frequently handle progress events and check for cancellation requests.
object CompileParameter()abstract function defined in ILAsyncAlgorithmconstruct input parameter object like expected from your implementation of the AlgorithmFunction
[yourType] Resultproperty---Cast back and return m_result variable from object to your return type [yourType]
OnAlgorithmFinished() [optional]virtual functiondefined in ILAsyncAlgorithmclean up after algorithm has finished successfully - [implementation is optional!]

The key to developing performance critical and/or long running algorithms is to carefully keep track of frequent signaling any user of state changes. The base class itself manages the firing of the StateChanged events. The developer of the derived algorithm class must implement the signaling of progress changes and keep track of the (safe) cancellation on user request. Therefore the ILAsyncAlgorithm class provides helper functions conveniently called from within your algorithm code:

nametypepurpose
CancelPendingprotected propertytrue if the user has requested cancellation. You should return as soon as possible.
SetProgressprotected functionFire ProgressChanged events. Report actual progress and additional data to users of your class having registered for the event.

Valid CSS! Valid XHTML 1.0 Transitional