DocumentationMonoBehaviourMultithreadedDisableMultithreading

DisableMultithreading

Temporarily stops recurring worker execution for the current component.

Instance methodC# API
void DisableMultithreading();

Description

Disables multithreading for this component and temporarily removes its registered recurring functions from the internal worker workflow. The registrations are retained, so they can be restored later with EnableMultithreading.

Temporary pauseRegistered functions are retained and can be re-enabled without calling AddFunction again.
Lifecycle useCalling this from OnDisable prevents a disabled component from continuing its recurring worker work.

Pause work with the component lifecycle

using ThreadHarmonizerEngine;
using UnityEngine;

public class BackgroundCalculation : MonoBehaviourMultithreaded
{
    private void Start()
    {
        AddFunction(ParallelUpdate);
    }

    private void ParallelUpdate()
    {
        // Perform recurring Unity-independent calculations here.
    }

    private void OnDisable()
    {
        DisableMultithreading();
    }

    private void OnEnable()
    {
        EnableMultithreading();
    }
}