Click or drag to resize

ThreadedCalculation Class

Parallelizes calculations across multiple threads. Most calculations can be parallelized using the static methods on this class. Or, in more advanced scenarios, derive from this class to implement a multithreaded calculation. Calculations are multithreaded according to the ThreadingPolicy.
Inheritance Hierarchy
SystemObject
  AGI.Foundation.Infrastructure.ThreadingThreadedCalculation

Namespace:  AGI.Foundation.Infrastructure.Threading
Assembly:  AGI.Foundation.Core (in AGI.Foundation.Core.dll) Version: 24.3.420.0 (24.3.420.0)
Syntax
public abstract class ThreadedCalculation : IDisposable

The ThreadedCalculation type exposes the following members.

Constructors
  NameDescription
Protected methodThreadedCalculation
Initializes a new instance.
Top
Properties
  NameDescription
Public propertyContinueExecution
Gets or sets a value indicating whether a thread should continue its threaded execution. It is the responsibility of derived classes to check this value in their ExecuteWorker(Int32) method and to stop their execution if it is false.
Public propertyMultithreadSubCalculations
Gets or sets a value indicating whether subcalculations should use the current ThreadingPolicy. By default, this is false, indicating that the subcalculations will see a ThreadingPolicy specifying that further operations be executed in the thread that invoked those operations. New threads created for use by the threaded calculation will use the default threading policy that was previously configured by calling UseCurrentAsDefault.
Public propertyNumberOfThreads
Gets the number of threads to be used to perform the calculation.
Top
Methods
  NameDescription
Public methodDispose
Releases any resources associated with this instance.
Protected methodDispose(Boolean)
Releases any resources associated with this instance.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodExecuteInOneThread
Starts the calculation using the calling thread as the one and only worker thread. This method does not return until the calculation is completed.
Protected methodExecuteWorker
Implement this method to perform the calculation. It is called NumberOfThreads times, each call in a separate thread.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Protected methodFinish
This method is called after all worker threads have finished executing. It Does nothing if not overridden by the derived class.
Public methodStatic memberForTParameter(Int32, Int32, TParameter, ITrackCalculationProgress, ThreadedCalculationBodyCallbackTParameter)
A 'for' loop that is parallelized among multiple threads according to the ThreadingPolicy active in the calling thread. The loop behaves as if written as for (int i = start; i < stop; ++i). Inside the body callback, the ThreadingPolicy will be configured to use only the calling thread for any further parallelizable operations. This usually improves performance by putting the parallelism where it is most useful: in the 'for' loop itself. However, if you do wish to parallelize operations invoked inside the 'for' loop, you must explicitly set the ThreadingPolicy inside the callback.
Public methodStatic memberForTParameter(Int32, Int32, TParameter, ITrackCalculationProgress, ThreadedCalculationBodyCallbackWithProgressTParameter)

A 'for' loop that is parallelized among multiple threads according to the ThreadingPolicy active in the calling thread. The loop behaves as if written as for (int i = start; i < stop; ++i). Inside the body callback, the ThreadingPolicy will be configured to use only the calling thread for any further parallelizable operations. This usually improves performance by putting the parallelism where it is most useful: in the 'for' loop itself. However, if you do wish to parallelize operations invoked inside the 'for' loop, you must explicitly set the ThreadingPolicy inside the callback.

The body of the 'for' loop is given an ITrackCalculationProgress instance that can be used to report detailed information about the progress of individual loop iterations. It is not recommended to use this overload when looping through a large number of iterations or when detailed information about the progress of individual iterations is not required, because there is some overhead to the detailed progress reporting.

Public methodStatic memberForTParameter1, TParameter2(Int32, Int32, TParameter1, TParameter2, ITrackCalculationProgress, ThreadedCalculationBodyCallback2TParameter1, TParameter2)
A 'for' loop that is parallelized among multiple threads according to the ThreadingPolicy active in the calling thread. The loop behaves as if written as for (int i = start; i < stop; ++i). Inside the body callback, the ThreadingPolicy will be configured to use only the calling thread for any further parallelizable operations. This usually improves performance by putting the parallelism where it is most useful: in the 'for' loop itself. However, if you do wish to parallelize operations invoked inside the 'for' loop, you must explicitly set the ThreadingPolicy inside the callback.
Public methodStatic memberForTParameter1, TParameter2(Int32, Int32, TParameter1, TParameter2, ITrackCalculationProgress, ThreadedCalculationBodyCallbackWithProgress2TParameter1, TParameter2)

A 'for' loop that is parallelized among multiple threads according to the ThreadingPolicy active in the calling thread. The loop behaves as if written as for (int i = start; i < stop; ++i). Inside the body callback, the ThreadingPolicy will be configured to use only the calling thread for any further parallelizable operations. This usually improves performance by putting the parallelism where it is most useful: in the 'for' loop itself. However, if you do wish to parallelize operations invoked inside the 'for' loop, you must explicitly set the ThreadingPolicy inside the callback.

The body of the 'for' loop is given an ITrackCalculationProgress instance that can be used to report detailed information about the progress of individual loop iterations. It is not recommended to use this overload when looping through a large number of iterations or when detailed information about the progress of individual iterations is not required, because there is some overhead to the detailed progress reporting.

Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStart
Starts the threaded calculation. This method returns immediately after creating the appropriate number of threads. It does not wait for the calculation to be completed.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodWaitUntilDone
Blocks the calling thread until the calculation has completed. If an exception occurs (or has already occurred) in any of the calculation threads, this method will throw a ThreadException wrapping the exception that was thrown by the calculation thread. The actual exception that occurred can be found in the InnerException property.
Top
See Also