问题描述:

I am using below code where in method startThread if I am using detachNewThreadSelector method, it blocks my UI but when I use to make object of NSThread and call start method and in that I called run method it is not blocking my UI.

What I am not getting is detachNewThreadSelector will run in background so it should not block my UI.then why so in my case?

and what is with start method and NSThread object? will it run in background or main thread?

I have search so many articles and StackOverFlow questions but not get in which senario actually these Threads workout

 -(void)startThread

{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

//NSThread *myThread = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:nil];

//[myThread start];

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

[pool release];

}

-(void)run:(id)param

{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

while (threadProgressView.progress < 1) {

[NSThread sleepForTimeInterval:0.25];

[self updateProgressBar];

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

}

threadStartButton.hidden = NO;

[pool release];

}

-(void)updateProgressBar

{

NSLog(@"In update progress bar");

float actual = [threadProgressView progress];

threadValueLabel.text = [NSString stringWithFormat:@"%.2f",actual];

threadProgressView.progress = actual + 0.025;

}

相关阅读:
Top