I have an NSImageView that needs to redraw a constantly updating image.
I have a model object that creates the NSImage, and a controller that links this image to the NSImageView.
With multithreading, I can easily have the model object continuously update its output image in a background thread. But as UI interactions are supposed to be done on the main thread, I can’t set the NSImageView’s image on a background thread. If I update the NSImageView on the main thread, the program would become unresponsive
I hate to be contradictory but why do you think that updating the image on the main thread would make the program unresponsive?
If calculating the next
NSImageis instantaneous then logically you should just calculate and display the last one since none of those in between will ever be perceived.If calculating the next one costs some time then do the calculation off the main thread then push the image to the view on the main thread (eg, using
performSelectorOnMainThread:...). The main thread won’t become unresponsive because it has all that time while you’re calculating the next image to deal with other events.If updates are more frequent than the display’s frame rate then you can probably go one better by setting yourself up with a
CVDisplayLinkand polling whatever is updating the image to get the latest one upon every tick of that.