running a blocking operation outside of main thread

I would like to perform a long blocking operation repeatedly -

Essentially take a screen grab, run a few operations, return back to the UI, update it and then repeat the process all over again.

What is the best procedure for this?


I used threads from here - Unity3D and C# - Coroutines vs threading - Questions & Answers - Unity Discussions But they did not work as expected had issues with memory management and calling .


I tried to use InvokeRepeating with coroutines but have not been able to do it


A few lines in pseudocode that I have tried -

void  Awake() {
    InvokeRepeating("DoJob", 0.0f , 10.0f);
}
//version 1
void DoJob(){
    //Long job // blocks thread
}
//version 2
void DoJob(){
    myJob.Start (); // memory problems
}

I am a noob and trying to look to learn how to go about this. Any pointers or resources will be extremely helpful

You can use the standard C# threading APIs in Unity, but you won’t have access to the Unity API (ie, no reference to GameObjects, Vector3, etc). Coroutines aren’t really threaded; they just perform operations over multiple frames. See this answer for a lot more detail.