- Home /
Limit rate that background thread works at
I have a thread that is created when a certain class is instantiated and contains a while loop. How can I make it so that the loop runs, at most, once per frame?
Answer by Joshua4missions · Aug 07, 2013 at 12:22 AM
At the end of your while loop add:
yield return; Or, if your loop already returns something, add "yield" before the return statement.
This will only allow the code to run up to once per frame.
I think he is talking about .NET threads, not Unity Coroutines.
Although if it's only running once per frame, it would probably be a good idea to use coroutines ins$$anonymous$$d of threads.
It's a .Net thread because it processes a lot of data when that data is marked on a queue. I can't use a coroutine because that runs on the main thread and would slow it down.