Hello everybody!
I am having a problem.
There is a part of my code where i need do deserialize a very big JSON.
Since it is a lot of effort to do that and I don’t want to stop the UI and other important stuff i decided to execute the serialization in a separate thread. And then callback to the main thread when the deserialization is complete.
But differently than what i expected, the UI and the rest of execution stops and wait for the deserialization to complete as if there were no separate thread.
Obs: The deserialization works fine. The problem is that the execution stops as if there were no threads.
My code is somewhat as follows:
IEnumerator DeserializeObjectAsync(string json,Action<MyObject> callback){
bool threadFinished = false;
MyObject deserializedObject = null;
Thread t = new Thread (delegate() {
deserializedObject = JsonUtility.FromJson<MyObject>(json);
threadFinished = true;
});
t.Start ();
while(!threadFinished){
yield return new WaitForEndOfFrame ();
}
callback(deserializedObject);
}
Does someone know what may be the issue or how to solve it?
Thank you!