Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's hard to say with certainty that this will work for your specific needs (since your specific needs may have main-thread dependencies not called out in your question) but I don't see anything particularly controversial here. For instance, the following code works just fine without incident:</p> <pre><code>CGImageRef CreateImageFromView(NSView* view) { const CGSize contextSize = CGSizeMake(ceil(view.frame.size.width), ceil(view.frame.size.height)); const size_t width = contextSize.width; const size_t height = contextSize.height; const size_t bytesPerPixel = 32; const size_t bitmapBytesPerRow = 64 * ((width * bytesPerPixel + 63) / 64 ); // Alignment CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, bitmapBytesPerRow, colorSpace, kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedLast); CGColorSpaceRelease(colorSpace); [view displayRectIgnoringOpacity: view.bounds inContext: [NSGraphicsContext graphicsContextWithGraphicsPort: context flipped: YES]]; CGImageRef image = CGBitmapContextCreateImage(context); CGContextRelease(context); return image; } - (IBAction)doStuff:(id)sender { static NSUInteger count = 0; for (NSUInteger i =0; i &lt; 100; ++i) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSButton* button = [[[NSButton alloc] initWithFrame: NSMakeRect(0, 0, 200, 100)] autorelease]; button.title = [NSString stringWithFormat: @"Done Stuff %lu Times", (unsigned long)count++]; CGImageRef image = CreateImageFromView(button); NSImage* nsImage = [[[NSImage alloc] initWithCGImage:image size: NSMakeSize(CGImageGetWidth(image), CGImageGetHeight(image))] autorelease]; CGImageRelease(image); dispatch_async(dispatch_get_main_queue(), ^{ self.imageView.image = nsImage; }); }); } } </code></pre> <p>The key here is that everything be "private" to the background rendering task. It gets its own view, its own graphics context, etc. If you aren't sharing anything, this should be OK. Since you explicitly said, "Given that each request is entirely separate, with nothing shared between them", I suspect you've already satisfied this condition.</p> <p>Try it out. Leave a comment if you run into trouble.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload