Documentation › EnqueueOnMainThread
EnqueueOnMainThread
Queues a Unity-side action for execution on the main thread without blocking the calling worker.
Instance method
Asynchronous
C# API
METHOD SIGNATURE
void EnqueueOnMainThread(Action function);
Description
Adds a parameterless action to ThreadHarmonizer’s main-thread queue. The calling worker continues without waiting, so use this for final Unity API writes after worker calculations are complete.
Non-blocking hand-off
The worker continues immediately after the action has been queued.
Unity-side apply
Place Transform, GameObject, component, and other Unity API writes inside the queued action.
Parameters
Name
Type
Description
function
Action
A parameterless action with no return value that will run on Unity’s main thread.
Code Example
EXAMPLE
using ThreadHarmonizerEngine;
using UnityEngine;
public class WorkerMovement : MonoBehaviourMultithreaded
{
private Vector3 m_cachedPosition;
private Vector3 m_nextPosition;
private void Start()
{
AddFunction(ParallelUpdate);
}
private void Update()
{
m_cachedPosition = transform.position;
}
private void ParallelUpdate()
{
m_nextPosition = m_cachedPosition + Vector3.right * 2f;
EnqueueOnMainThread(() =>
{
transform.position = m_nextPosition;
});
}
}
