Unity job still runs on main thread or doesn't work

I’m trying to bake my meshes on a different thread with Unity jobs mainly going off of this page in the Unity docs. My code looks like this:

public struct BakeJob2 : IJob
    public int meshId;

    public void Execute()
        Physics.BakeMesh(meshId, false);

and calling the job like this:

        NativeArray<int> meshId = new NativeArray<int>(1, Allocator.TempJob);

        meshId[0] = mesh.GetInstanceID();
        var job = new BakeJob2();
        job.meshId = meshId[0];


        meshCollider.sharedMesh = mesh;

My profiler looks like this:

As you can see, Physics.BakeMesh is still running on the main thread, my other “jobs” threads are on idle. So I think my job is just not executing and the Physics.BakeMesh is getting called from the meshCollider.sharedMesh = mesh. If the mesh data is already available it won’t rebake the mesh. I think there are a few things I am probably doing wrong but I should at least get the thread to run before going further. What am I doing wrong? Thank you.

For one, in this case because you are only using one mesh the NativeArray isn’t necessary; and you aren’t actually using it, just allocating it then copying data into and immediately out of it.

var job = new BakeJob2();
job.meshId = mesh.GetInstanceID();

As for why the job is running synchronously - you schedule it which will start it on a background thread when ready, but then immediately complete it which will cause the main thread to wait until it has finished executing. If you want it to run asynchronously, then you will need to start the job and wait until it is finished (or at least has had time to run) before completing it;

job.Schedule ();

StartCoroutine (WaitForJob ());
IEnumerator WaitForJob ()
    //Wait for the job to finish
    yield return new WaitUntil (() => job.IsCompleted);
    //Then call Complete() to make sure everything is available for the main thread
    job.Complete ();

    meshCollider.sharedMesh = mesh;