English 中文(简体)
关于背景更新的通知
原标题:Notification on background thread updates NSView

There is a task needs to draw N images on a NSView. But at the beginning I do not know the amount of images, so I set it works in a thread of background.

 [NSThread detachNewThreadSelector:@selector(workInBackgroundThread:) toTarget:self withObject:nil];

在获得图像数量时,它将发出通知。

- (void)workInBackgroundThread:(id)unusedObject {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

//get image amount....

[[NSNotificationCenter defaultCenter] postNotificationName:@"gotImageAmount" object:nil];

//...
//continue to load images

}

我试图将NSView重新定位,取决于通知职能中的图像数量。

-(void)processGotImagesAmount:(NSNotification*)notification  
{

    //others codes

    [myNSView setFrame:CGRectMake(0,   0, calculateNewWidth, caculatedNewHeight)];//line A

    //others codes

}

但是,当这些评估执行A线时,它冻结了,

[myNSView setFrame:CGRectMake(0,   0, calculateNewWidth, caculatedNewHeight)];

如果我点击一个叫它的人,那就没有问题了。

但它认为它不履行通知职能。

欢迎任何意见

最佳回答
问题回答

暂无回答




相关问题
Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Is reading from an XmlDocument object thread safe?

I was wondering if i could safely read from an XmlDocument object using SelectNodes() and SelectSingleNode() from multiple threads with no problems. MSDN says that they are not guaranteed to be ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签