Click or drag to resize
AB4D logo

BackgroundThreadsManager Class

BackgroundThreadsManager can be used to create multiple threads and execute custom actions on them.
Inheritance Hierarchy
SystemObject
  Ab3d.DirectX.ThreadingBackgroundThreadsManager

Namespace: Ab3d.DirectX.Threading
Assembly: Ab3d.DXEngine (in Ab3d.DXEngine.dll) Version: 7.0.8865.1045
Syntax
C#
public class BackgroundThreadsManager : IDisposable

The BackgroundThreadsManager type exposes the following members.

Constructors
 NameDescription
Public methodBackgroundThreadsManager Constructor
Top
Properties
 NameDescription
Public propertyThreadAbortDelayMs Gets or sets a integer value that specifies the number of milliseconds that are used to delay the call to Thread.Abort method after the thread is not used any more. This is used to prevent creation and abortion of threads when the number of used threads is changing rapidly because the number of rendered objects is also changing. Default value is 1000 and delays the thread abortion for 1 second. Zero value means that the unused threads are immediately aborted. To immediately abort unused threads, set ThreadAbortDelayMs to 0 and then call SetupThreads(Int32) method.
Public propertyThreadsCount Gets the number of currently active background threads (including the threads that are schedules to be aborted).
Top
Methods
 NameDescription
Public methodDispose Dispose
Public methodExecute Execute method executes the specified taskAction on all threads that were before set up with calling the SetupThreads(Int32) method. The taskAction gets a thread index as parameter.
Public methodGetException GetException returns an Exception object for the thread with the specified index. If no exception was thrown by this thread, then null is returned.
Public methodHasExceptions HasExceptions returns true if any executed action has thrown an exception.
Public methodSetupThreads SetupThreads sets up the background threads based on the specified threadsCount. When the number of currently created background threads is bigger then the specified threadsCount, the unused threads are scheduled to be aborted (see ThreadAbortDelayMs). To immediately abort unused threads set ThreadAbortDelayMs to 0 before calling this method.
Public methodWaitAll Waits indefinitely until all taskActions that were passed to the Execute(BackgroundTaskStartDelegate) method are completed.
Public methodWaitAll(Int32) Waits until all taskActions that were passed to the Execute(BackgroundTaskStartDelegate) method are completed. If the this takes longer than the millisecondsTimeout, the methods returns with false value.
Top
Remarks

BackgroundThreadsManager can be used to create multiple threads and execute custom actions on them.

To set up the number of required threads call the SetupThreads(Int32) method. Then you can call the Execute(BackgroundTaskStartDelegate) method to executed the specified action on all set up threads. When number of threads in the call to the SetupThreads(Int32) method is lower then the number specified in the previous call, the unused threads are not immediately aborted but instead they are scheduled to be aborted after the ThreadAbortDelayMs time.

You can derive your own class from BackgroundThreadsManager and override the SetupThreads, Execute, WaitAll and Dispose methods to provide you own threading mechanism.

IMPORTANT: The methods in this class are not thread safe and must be called only from one thread.

See Also