i want to block the main thread until something else is done in the background.
i used:
result=[self performSelectorInBackground:@selector(calculate:) withObject:expression];
just bellow this line I am using result:
[self use:result];
i dont want to use result until it is available.
to achieve this I implemented
-calculate:
{
[[(AppDelegate *)[[UIApplication sharedApplication] delegate] queue] waitUntilAllOperationsAreFinished];
calculating result...
}
and still, the result is used before it is calculated. so, i didnt block the main thread. pls help me do that.
thanks
You don’t want to block the main thread; it will prevent users from using the UI.
What you want is to use the result obtained in the background once it’s ready.
One method is to call
-use:at the end of the method called in the background: you definethen you just call from the main thread
This way, you can achieve what you want without blocking the main thread.
By the way,
-performSelectorInBackgronudhas nothing to do withNSOperationQueue. So[queue waitUntilAllOperationsAreFinished]doesn’t wait the execution of the method invoked by-performSelectorInBackground.And in any case, you shoudln’t call
waitUntilAllOperationAreFinishedunless absolutely necessary.To know when an
NSOperationis done, you KVC the propertyisFinished. See the NSOperation reference.