- Home /
Why does a background Thread block rendering?
First of, I'm well aware that Unity is not thread safe, but I am doing some background processing in a thread which is later used in Unity in a thread safe way (I'm making a web request for data I need during runtime).
I am starting the thread like this (slimmed down for clarity):
public IEnumerator StartThreadRequest()
{
System.Threading.Thread t = new System.Threading.Thread(() =>
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
Thread.Sleep(10000); // long running web request simulated with sleep.
}
});
t.Start();
// both the while loop and the below t.Join() will block rendering (tried them both separatly).
while (t.IsAlive == true) {
Thread.Sleep(2);
}
t.Join ();
yield return null;
}
// The above method is called from the Start method in a
// class implementing : MonoBehaviour as a coroutine
StartCoroutine(StartThreadRequest());
Why does this block rendering, and how do I let the rendering continue.
When this is run the game basically freezes.
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Update Method doesn't see value set by other thread 0 Answers
object cleanup when not relevant 0 Answers