CancelAllTasks

CancelAllTasks

#Overview

name: CancelAllTasks

This variable is created as a Console Variable (cvar).

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of CancelAllTasks is to provide a mechanism for canceling all ongoing tasks in the Unreal Engine’s Interchange system and Editor Utility subsystem. This function is primarily used for task management and control flow in asynchronous operations.

The Unreal Engine subsystems that rely on this variable are:

  1. Editor Utility Subsystem (EditorUtilitySubsystem)
  2. Interchange Engine Module (InterchangeManager)

The value of this variable is not set directly, as it’s not a variable but a function or command. It’s invoked in different contexts:

  1. In the Editor Utility Subsystem, it’s registered as a console command.
  2. In the Interchange Manager, it’s a method that can be called to cancel all tasks.

Other variables and functions that interact with CancelAllTasks include:

  1. WaitUntilAllTasksDone function, which may call CancelAllTasks
  2. SetActiveMode function, which may call CancelAllTasks based on user notification response

Developers must be aware of the following when using CancelAllTasks:

  1. It’s an asynchronous operation in the Interchange Manager.
  2. It’s designed to work with the task queue system in the Interchange Manager.
  3. In the Editor Utility Subsystem, it’s exposed as a console command.

Best practices when using CancelAllTasks:

  1. Ensure it’s called from the game thread in the Interchange Manager (there’s a check for this).
  2. Be prepared to handle the aftermath of canceling all tasks, such as cleaning up resources or notifying users.
  3. Use it judiciously, as canceling all tasks may disrupt ongoing operations.
  4. When used in the Editor Utility Subsystem, be aware that it’s available as a console command and could be invoked by users.
  5. Consider the impact on performance and user experience when canceling all tasks, especially in the middle of complex operations.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Editor/Blutility/Private/EditorUtilitySubsystem.cpp:64

Scope (from outer to inner):

file
function     void UEditorUtilitySubsystem::Initialize

Source code excerpt:


	CancelAllTasksCommandObject = IConsoleManager::Get().RegisterConsoleCommand(
		TEXT("CancelAllTasks"),
		TEXT(""),
		FConsoleCommandWithWorldArgsAndOutputDeviceDelegate::CreateUObject(this, &UEditorUtilitySubsystem::CancelAllTasksCommand),
		ECVF_Default
	);

	IMainFrameModule& MainFrameModule = IMainFrameModule::Get();
	if (MainFrameModule.IsWindowInitialized())
	{
		HandleStartup();
	}
	else

#Loc: <Workspace>/Engine/Source/Runtime/Interchange/Engine/Private/InterchangeManager.cpp:2420

Scope (from outer to inner):

file
function     void UInterchangeManager::CancelAllTasks

Source code excerpt:

}

void UInterchangeManager::CancelAllTasks()
{
	check(IsInGameThread());

	//Cancel the queued tasks, we cannot simply not do them since, there is some promise objects
	//to setup in the completion task
	constexpr bool bCancelAllTasks = true;

#Loc: <Workspace>/Engine/Source/Runtime/Interchange/Engine/Private/InterchangeManager.cpp:2462

Scope (from outer to inner):

file
function     void UInterchangeManager::WaitUntilAllTasksDone

Source code excerpt:

	{
		//Start the cancel process by cancelling all current task
		CancelAllTasks();
	}

	while (ImportTasks.Num() > 0)
	{
		TSharedPtr<UE::Interchange::FImportAsyncHelper, ESPMode::ThreadSafe> AsyncHelper = ImportTasks[0];
		if (AsyncHelper.IsValid())

#Loc: <Workspace>/Engine/Source/Runtime/Interchange/Engine/Private/InterchangeManager.cpp:2496

Scope (from outer to inner):

file
function     void UInterchangeManager::SetActiveMode
lambda-function

Source code excerpt:

			if (Notification.IsValid() && Notification->GetPromptAction() == EAsyncTaskNotificationPromptAction::Cancel)
			{
				CancelAllTasks();
			}
			return true;
		});
	}
	else
	{

#Loc: <Workspace>/Engine/Source/Runtime/Interchange/Engine/Public/InterchangeManager.h:672

Scope (from outer to inner):

file
class        class UInterchangeManager : public UObject

Source code excerpt:

	 * @note - This is a asynchronous call. Tasks will be completed (canceled) soon.
	 */
	INTERCHANGEENGINE_API void CancelAllTasks();

	/**
	 * Wait synchronously until all tasks are done.
	 */
	INTERCHANGEENGINE_API void WaitUntilAllTasksDone(bool bCancel);