System.Threading.TTask

From RAD Studio API Documentation
Jump to: navigation, search

System.Threading.TAbstractTaskSystem.Threading.TThreadPool.TAbstractWorkerDataSystem.TInterfacedObjectSystem.TObjectTTask

Delphi

TTask = class(TAbstractTask, TThreadPool.IThreadPoolWorkItem, ITask, TAbstractTask.IInternalTask)

C++

class PASCALIMPLEMENTATION TTask : public TAbstractTask

Properties

Type Visibility Source Unit Parent
class public
System.Threading.pas
System.Threading.hpp
System.Threading System.Threading

Description

TTask is a class managing and representing procedures that can be executed in parallel threads.

An instance of TTask represents a single task or unit of work to be done in a thread parallel to other running tasks, if possible.

The TTask class creates and manages task instances represented by the ITask interface, which can be instances of TTask, its descendant types, or other types compatible with the ITask interface.

The procedure associated with a task may run in parallel with those associated with other similar tasks and other threads currently running. What tasks will run in parallel and when they will run depend upon the threading resources available to the run-time environment of the target platform.

Tasks suitable for parallel execution can be created using the Create constructor. The task procedures provided to the constructor are considered ready for execution after calling the Start method.

The WaitForAll, WaitForAny, and the Wait methods of ITask are used to explicitly suspend execution of the calling thread to wait upon any or all running tasks.

To cancel the execution of any task, call the Cancel method of the relevant instance of ITask.

A task procedure can be created and managed for execution directly using the Run method, similarly to calling Create immediately followed by Start.

For tasks where a return value is needed at some later point in the program, the generic function, Future, can be used to launch the task to determine the needed value in parallel with other tasks; this value is then retrieved later where required by calling its GetValue method.

If tasks that may execute in parallel require globally available resources, variables, etc., use the synchronization tools of the System.SyncObjs unit to avoid possible contention issues.

See also