Search Results for

    Show / Hide Table of Contents

    Class Task

    Represents an asynchronous operation.

    Inheritance
    Object
    Task
    Inherited Members
    Object::DeleteObject(float timeToLive = 0.0f, bool useGameTime=false)
    Object::DeleteObjectNow()
    Object::Flags
    NonCopyable::NonCopyable()
    NonCopyable::NonCopyable(const NonCopyable& )
    Object::OnDeleteObject()
    NonCopyable::operator=(const NonCopyable& )
    Object::ToString()
    Object::~Object()
    Assembly: FlaxEngine.dll
    File: Engine/Threading/Task.h
    Syntax
    public class Task : public Object, public NonCopyable

    Fields

    _cancelFlag

    The cancel flag used to indicate that there is request to cancel task operation.

    Declaration
    protected int64 _cancelFlag = 0
    Field Value
    int64

    _continueWith

    The task to start after finish.

    Declaration
    protected Task* _continueWith = nullptr
    Field Value
    Task

    _state

    The current task state.

    Declaration
    protected TaskState _state = TaskState::Created
    Field Value
    TaskState

    Methods

    Cancel()

    Cancels this task (and all child tasks).

    Declaration
    public void Cancel()

    CancelAll(Array<T* , AllocationType>& tasks)

    Cancels all the tasks from the list and clears it.

    Declaration
    public static void CancelAll(Array<T* , AllocationType>& tasks)
    Parameters
    Array<T , AllocationType> tasks

    Type Parameters
    class T

    typename AllocationType

    ContinueWith(const Action& action, Object* target=nullptr)

    Continues that task execution with a given action (will spawn new async action).

    Declaration
    public Task* ContinueWith(const Action& action, Object* target=nullptr)
    Parameters
    Action action

    Action to run.

    Object target

    The action target object.

    Returns
    Task

    Enqueued task.

    ContinueWith(const Function<bool()>& action, Object* target=nullptr)

    Continues that task execution with a given action (will spawn new async action).

    Declaration
    public Task* ContinueWith(const Function<bool()>& action, Object* target=nullptr)
    Parameters
    Function<bool()> action

    Action to run.

    Object target

    The action target object.

    Returns
    Task

    Enqueued task.

    ContinueWith(const Function<void()>& action, Object* target=nullptr)

    Continues that task execution with a given action (will spawn new async action).

    Declaration
    public Task* ContinueWith(const Function<void()>& action, Object* target=nullptr)
    Parameters
    Function<void()> action

    Action to run.

    Object target

    The action target object.

    Returns
    Task

    Enqueued task.

    ContinueWith(Task* task)

    Continues that task execution with a given task (will call Start on given task after finishing that one).

    Declaration
    public Task* ContinueWith(Task* task)
    Parameters
    Task task

    The task to Start after current finish (will propagate OnCancel event if need to).

    Returns
    Task

    Enqueued task.

    Enqueue()

    Declaration
    protected virtual void Enqueue() = 0

    Execute()

    Executes this task. It should be called by the task consumer (thread pool or other executor of this task type). It calls run() and handles result).

    Declaration
    protected void Execute()

    GetContinueWithTask()

    Gets the task to start after this one.

    Declaration
    public Task* GetContinueWithTask() const
    Returns
    Task

    GetState()

    Gets the task state.

    Declaration
    public TaskState GetState() const
    Returns
    TaskState

    HasReference(Object* obj)

    Determines whether the specified object has reference to the given object.

    Declaration
    public virtual bool HasReference(Object* obj) const
    Parameters
    Object obj

    The object.

    Returns
    bool

    True if the specified object has reference to the given object, otherwise false.

    IsCanceled()

    Checks if operation has been canceled.

    Declaration
    public bool IsCanceled() const
    Returns
    bool

    IsCancelRequested()

    Returns true if task has been requested to cancel it's operation.

    Declaration
    public bool IsCancelRequested()
    Returns
    bool

    IsEnded()

    Checks if operation has been ended (via cancel, fail or finish).

    Declaration
    public bool IsEnded() const
    Returns
    bool

    IsFailed()

    Checks if operation failed.

    Declaration
    public bool IsFailed() const
    Returns
    bool

    IsFinished()

    Checks if operation has been finished.

    Declaration
    public bool IsFinished() const
    Returns
    bool

    IsQueued()

    Checks if operation has been queued.

    Declaration
    public bool IsQueued() const
    Returns
    bool

    IsRunning()

    Checks if operation is running.

    Declaration
    public bool IsRunning() const
    Returns
    bool

    OnCancel()

    Declaration
    protected virtual void OnCancel()

    OnEnd()

    Declaration
    protected virtual void OnEnd()

    OnFail()

    Declaration
    protected virtual void OnFail()

    OnFinish()

    Declaration
    protected virtual void OnFinish()

    OnStart()

    Declaration
    protected virtual void OnStart()

    Run()

    Runs the task specified operations. It does not handle any task related logic, but only performs the actual job.

    Declaration
    protected virtual bool Run() = 0
    Returns
    bool

    The task execution result. Returns true if failed, otherwise false.

    SetState(TaskState state)

    Declaration
    protected void SetState(TaskState state)
    Parameters
    TaskState state

    Start()

    Starts this task execution (and will continue with all children).

    Declaration
    public void Start()

    StartNew(const Function<bool()>& action, Object* target=nullptr)

    Starts the new task.

    Declaration
    public static Task* StartNew(const Function<bool()>& action, Object* target=nullptr)
    Parameters
    Function<bool()> action

    The action.

    Object target

    The action target object.

    Returns
    Task

    Task

    StartNew(const Function<void()>& action, Object* target=nullptr)

    Starts the new task.

    Declaration
    public static Task* StartNew(const Function<void()>& action, Object* target=nullptr)
    Parameters
    Function<void()> action

    The action.

    Object target

    The action target object.

    Returns
    Task

    Task

    StartNew(Function<bool()>::Signature& action, Object* target=nullptr)

    Starts the new task.

    Declaration
    public static Task* StartNew(Function<bool()>::Signature& action, Object* target=nullptr)
    Parameters
    Function<bool()>::Signature action

    The action.

    Object target

    The action target object.

    Returns
    Task

    Task

    StartNew(Function<void()>::Signature action, Object* target=nullptr)

    Starts the new task.

    Declaration
    public static Task* StartNew(Function<void()>::Signature action, Object* target=nullptr)
    Parameters
    Function<void()>::Signature action

    The action.

    Object target

    The action target object.

    Returns
    Task

    Task

    StartNew(T* callee)

    Starts the new task.

    Declaration
    public static Task* StartNew(T* callee)
    Parameters
    T callee

    The callee object.

    Returns
    Task

    Task

    Type Parameters
    class T

    Method

    StartNew(Task* task)

    Starts the new task.

    Declaration
    public static Task* StartNew(Task* task)
    Parameters
    Task task

    The task.

    Returns
    Task

    Task

    Wait(const TimeSpan& timeout)

    Waits the specified timeout for the task to be finished.

    Declaration
    public bool Wait(const TimeSpan& timeout) const
    Parameters
    TimeSpan timeout

    The maximum amount of time to wait for the task to finish it's job. Timeout smaller/equal 0 will result in infinite waiting.

    Returns
    bool

    True if task failed or has been canceled or has timeout, otherwise false.

    Wait(double timeoutMilliseconds=-1)

    Waits the specified timeout for the task to be finished.

    Declaration
    public bool Wait(double timeoutMilliseconds=-1) const
    Parameters
    double timeoutMilliseconds

    The maximum amount of milliseconds to wait for the task to finish it's job. Timeout smaller/equal 0 will result in infinite waiting.

    Returns
    bool

    True if task failed or has been canceled or has timeout, otherwise false.

    WaitAll(const Array<T* , AllocationType>& tasks, double timeoutMilliseconds=-1)

    Waits for all the tasks from the list.

    Declaration
    public static bool WaitAll(const Array<T* , AllocationType>& tasks, double timeoutMilliseconds=-1)
    Parameters
    Array<T , AllocationType> tasks

    The tasks list to wait for.

    double timeoutMilliseconds

    The maximum amount of milliseconds to wait for the task to finish it's job. Timeout smaller/equal 0 will result in infinite waiting.

    Returns
    bool

    True if any task failed or has been canceled or has timeout, otherwise false.

    Type Parameters
    class T

    typename AllocationType

    WaitAll(const Span<Task* >& tasks, double timeoutMilliseconds=-1)

    Waits for all the tasks from the list.

    Declaration
    public static bool WaitAll(const Span<Task* >& tasks, double timeoutMilliseconds=-1)
    Parameters
    Span<Task > tasks

    The tasks list to wait for.

    double timeoutMilliseconds

    The maximum amount of milliseconds to wait for the task to finish it's job. Timeout smaller/equal 0 will result in infinite waiting.

    Returns
    bool

    True if any task failed or has been canceled or has timeout, otherwise false.

    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat