Documentation › ThreadHarmonizerManager.EnqueueOnMainThread
EnqueueOnMainThread
Queues a Unity-side action on the main thread from scripts that do not inherit from MonoBehaviourMultithreaded.
Static method
Asynchronous
C# API
METHOD SIGNATURE
static void EnqueueOnMainThread(Action function);
Description
Adds a parameterless action to the shared main-thread queue. The calling worker continues without waiting, making this the static hand-off for final Unity API operations.
No special inheritance
The static API can be used from ordinary MonoBehaviour classes and other compatible code.
Non-blocking apply
The worker queues the action and continues immediately.
Parameters
Name
Type
Description
function
Action
A parameterless action with no return value that will execute on Unity’s main thread.
Code Example
EXAMPLE
using ThreadHarmonizerEngine;
using UnityEngine;
public class StaticMainThreadApply : MonoBehaviour
{
private Vector3 m_startPosition;
private void Start()
{
m_startPosition = transform.position;
ThreadHarmonizerManager.EnqueueOnWorker(() =>
{
Vector3 nextPosition = m_startPosition + Vector3.right * 2f;
ThreadHarmonizerManager.EnqueueOnMainThread(() =>
{
transform.position = nextPosition;
});
});
}
}
