Hi, all! I want to create multiple threads in my application. I' using following code for creating a thread. This' buttonPress method where I'm creating a thread:
(void) threadButtonPressed:(UIButton *)sender {
threadStartButton.hidden = YES;
threadValueLabel.text = @"0";
threadProgressView.progress = 0.0;
[NSThread detachNewThreadSelector:@selector(startMethod) toTarget:self withObject:nil];
}
This' where I'm calling the method for the thread:
(void)startMethod {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(threadMethod) withObject:nil waitUntilDone:NO];
[pool release];
}
(void)threadMethod {
float actual = [threadProgressView progress];
threadValueLabel.text = [NSString stringWithFormat:@"%.2f", actual];
if (actual < 1) {
threadProgressView.progress = actual + 0.01; [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
else threadStartButton.hidden = NO;
}
This thread works properly. But when I try to create another thread in the same class using the same method, it gets created properly, but at the method "performSelectorOnMainThread", it doesn't execute that method. Can anybody please help me?