I’m trying to call upon a method within a class of mine which runs a while loop until it finds what it’s looking for.
The problem is that as soon as the loop starts, the engine freezes until the loop finishes. I essentially want this method to run in the background.
Is the only solution to run the class on a separate thread? If I do this, wouldn’t the parent that called the class to start on a new thread cause the game to freeze anyway while it waits for that thread’s result?
I’m just confused about all of this as I’ve never learned multi-threading before, and I haven’t really found any good documentation for implementing it so far (that I could understand).
I may be overcomplicating the question, but my goal is to have a single loop going on in the background, and it will essentially control itself.
Just as this answer says, you’re going to want a separate thread. But doing so has its own set of consequences. Multithreaded programming has a relatively high learning curve, so it’s going to be tricky if you’re not used to it.
It took me quite some time, but I’ve finally managed to figure out how to implement the class onto a separate thread.
I just had to more carefully examine Rama’s code. I suppose I was just intimidated by the fact that he had his own goal of working with prime numbers in addition to displaying the multi-threading code, and I didn’t include all the needed elements.