![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <AsyncWork.h>
Inheritance diagram for FAsyncTaskBase:Protected Member Functions | |
| void | Init (TStatId InStatId) |
| void | CheckIdle () const |
| virtual void | DoTaskWork ()=0 |
| virtual bool | TryAbandonTask ()=0 |
| virtual void | MarkAsCanceled () |
FAsyncTask - template task for jobs queued to thread pools
Sample code:
class ExampleAsyncTask : public FNonAbandonableTask
{
friend class FAsyncTask<ExampleAsyncTask>;
int32 ExampleData;
ExampleAsyncTask(int32 InExampleData)
: ExampleData(InExampleData)
{
}
void DoWork()
{
... do the work here
}
FORCEINLINE TStatId GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(ExampleAsyncTask, STATGROUP_ThreadPoolAsyncTasks);
}
};
void Example()
{
start an example job
FAsyncTask<ExampleAsyncTask>* MyTask = new FAsyncTask<ExampleAsyncTask>( 5 );
MyTask->StartBackgroundTask();
–or –
MyTask->StartSynchronousTask();
to just do it now on this thread Check if the task is done :
if (MyTask->IsDone())
{
}
Spinning on IsDone is not acceptable( see EnsureCompletion ), but it is ok to check once a frame. Ensure the task is done, doing the task on the current thread if it has not been started, waiting until completion in all cases.
MyTask->EnsureCompletion();
delete Task;
}
|
inlinevirtual |
Destructor, not legal when a task is in process
|
inline |
Cancel the task, if possible. Note that this is different than abandoning (which is called by the thread pool at shutdown).
Perform task's work
Implemented in FAsyncTask< TTask >, FAsyncTask< Audio::FAsyncDecodeWorker >, FAsyncTask< Chaos::FPersistentPhysicsTask >, FAsyncTask< FAsyncRealtimeAudioTaskWorker< T > >, FAsyncTask< FAudioAnalyzeTask >, FAsyncTask< FD3D12PipelineStateWorker >, FAsyncTask< FDoWorkTask >, FAsyncTask< FGenericReadRequestWorker >, FAsyncTask< FMicrosoftReadRequestWorker >, FAsyncTask< FRenderAssetStreamingMipCalcTask >, FAsyncTask< FResolveInfoAsyncWorker >, FAsyncTask< FVulkanAsyncPoolSetDeletionWorker >, and FPSOPrecacheAsyncTask.
|
inline |
Wait until the job is complete
| bDoWorkOnThisThreadIfNotStarted | if true and the work has not been started, retract the async task and do it now on this thread |
| specifies | if waiting for the task should return as soon as possible even if this delays other tasks |
|
inlinefinalvirtual |
Returns text to identify the Work, for debug/log purposes only
Reimplemented from IQueuedWork.
|
inline |
|
inlinefinalvirtual |
Returns an approximation of the peak memory (in bytes) this task could require during it's execution.
Reimplemented from IQueuedWork.
|
inline |
Returns true if the work and TASK has completed, false while it's still in progress. prior to returning true, it synchronizes so the task can be destroyed or reused
|
inline |
Returns true if the work has not been started or has been completed. NOT to be used for synchronization, but great for check()'s
|
inline |
Returns true if the work has completed, false while it's still in progress. This does not block and if true, you can use the results. But you can't destroy or reuse the task without IsDone() being true or EnsureCompletion()
Mark the task as canceled (i.e. no longer needed).
|
inline |
If not already being processed, will be rescheduled on given thread pool and priority.
|
inline |
|
inline |
Queue this task for processing by the background thread pool
|
inline |
Run this task on this thread
| bDoNow | if true then do the job now instead of at EnsureCompletion |
Abandon task if possible, returns true on success, false otherwise.
Implemented in FAsyncTask< TTask >, FAsyncTask< Audio::FAsyncDecodeWorker >, FAsyncTask< Chaos::FPersistentPhysicsTask >, FAsyncTask< FAsyncRealtimeAudioTaskWorker< T > >, FAsyncTask< FAudioAnalyzeTask >, FAsyncTask< FD3D12PipelineStateWorker >, FAsyncTask< FDoWorkTask >, FAsyncTask< FGenericReadRequestWorker >, FAsyncTask< FMicrosoftReadRequestWorker >, FAsyncTask< FRenderAssetStreamingMipCalcTask >, FAsyncTask< FResolveInfoAsyncWorker >, FAsyncTask< FVulkanAsyncPoolSetDeletionWorker >, and FPSOPrecacheAsyncTask.
Wait until the job is complete, up to a time limit
| TimeLimitSeconds | Must be positive, otherwise polls – same as calling IsDone() |