I have a few method calls like this:
[self myFoo];
[self heavyStuff]; // this one in other thread
[self myBar];
which classes / methods do I have to look at? When I search for "thread", there comes a lot of classes, methods and functions. Which one's are most apropriate here?
Here is the main method which can run a method in a separate thread: This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
If you want to make code only run once, you could have code in the method overwrite the method with NOP's after the method is complete. This way if the method were to run again, nothing would happen. This will break a few architectures that write protect program memory or run from ROM.
Put the code you want to run in the run() method - that's the method that you must write to comply to the Runnable interface. In your "main" thread, create a new Thread class, passing the constructor an instance of your Runnable, then call start() on it.
In your "main" thread, create a new Thread class, passing the constructor an instance of your Runnable, then call start () on it. start tells the JVM to do the magic to create a new thread, and then call your run method in that new thread. Take a look at Java's concurrency tutorial to get started.
You would do
[self performSelectorInBackground:@selector(heavyStuff) withObject:nil];
See the NSObject reference on Apple's site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With