-(void)test
{
int i;
for (i=0;i < 1000000;i++)
{
//do lengthly operation
}
}
How to prevent its GUI from freezing ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Bottom line; don’t block the main thread and, thus, don’t block the main event loop.
Now, you could spawn a thread. But that isn’t actually the correct way write concurrent programs on Mac OS X.
Instead, use NSOperation and NSOperationQueue. It is specifically designed to support your concurrent programming needs, it scales well, and NSOperationQueue is tightly integrated into the system such that it will control concurrency based on system resources available (# of cores, CPU load from other applications, etc) more efficiently than any direct use of threads.
See also the Threaded Programming Guide.