Help Threading Libnoise .net

Hello,
I’m trying to thread Libnoise so that unity won’t freeze while it generates maps. I have no experience threading; though, I’ve done my reading on the topic. As far as I can tell its working, as in libnoise is working in its own thread but unity still stops rendering frames for the duration.
In update, on event:

            Thread t = new Thread(() => { Generate(); }); // Generate sets up a Noise2D w/ LibNoise
            t.IsBackground = true; // do I need this? It should be a background process but...
            t.Start();
            while (t.IsAlive) Thread.Sleep(100);
            SetTexture(); // updates an objects texture

I want generate to run concurrent to unity’s main thread. Any advice?

you could probably do it with the help of coroutines

void Update()
{
    if( someCondition )
        StartCourotine( DoWork );
}
IEnumerator DoWork()
{
    Thread t = new Thread(() => { Generate(); }); // Generate sets up a Noise2D w/ LibNoise
    t.IsBackground = true; // do I need this? It should be a background process but...
    t.Start();
    while (t.IsAlive)
        yield return null // wait 1 frame
   SetTexture(); // updates an objects texture
}
2 Likes

Works perfectly, thank you.