在我的代码中,我进行了子类化NSView
,在它的drawRect
方法中,我产生了三个线程来执行绘图。
-(void)drawRect:(NSRect)dirtyRect
{
[[self window] setAllowsConcurrentViewDrawing:YES];
[self setCanDrawConcurrently:YES];
[NSThread detachNewThreadSelector:@selector(DrawText) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(DrawRectangle) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(DrawGradient) toTarget:self withObject:nil];
//Wherease these functions DrawText, DrawRectangle and DrawGradient performs their task as suggested by name.
//In DrawText, DrawRectangle, and DrawGradient lockFocus and unlockFocus is being
// used for multithreaded drawing.
}
当我从 Xcode 运行相同的程序时,它运行良好。输出如下所示。
但是当我从外部运行它时,出现了问题,输出如下所示。
首先,我想知道从辅助线程中提取是否正确?或者从辅助线程中提取的另一种方法是什么?
这个问题背后的原因是什么?