views:

127

answers:

3

Hello guys!

The reference says this: "You should call this function from the main thread of your application only."
But I would like to get the current graphics context from separate threads. What do you think? What can I do to reach this?


Edit: Thanks guys for the answers. I don't know which is good for me at the moment, but thank you very much.

A: 

I would say restructure your logic to conform to the reference's advice.

Generally it is accurate about things you should and shouldn't do.

Why do you want to access it from different threads?

Chris Cooper
I would like to draw PDF documents in 3 or 6 different views using threads. So can you suggest me an other way? I wouldn't like to create UIImages first and then add them into the view. Is there any good solution?
Infinity
+3  A: 

Never draw to the screen from anything other than the main thread!!! The graphics chip is single threaded, so you could cause all kinds of race conditions if you don't follow that rule.

You can draw to a background NSImage and then notify the main thread when you're finished and to update the screen.

jarjar
+1  A: 

If you want to draw from other threads, either create your own CGBitmapContext or use a CATiledLayer.

drawnonward
This is the correct answer. Create your own CGBitmapContext. See the Quartz drawing guide for examples.
orange
CGBitmapContext is also good, but CATiledLayer is better for me. :)Also I would recommend to others who wants to work with pdfs to work with CATiledLayer.
Infinity