views:

133

answers:

2

How to use performSelector:onThread:withObject:waitUntilDone:? here in onthread i have to use other thread not main thread. How to create other thread? give me some sample code.

+2  A: 

Unless you have a thread pool to manage, it's easier to use -performSelectorInBackground:…:

[object performSelectorInBackground:@selector(method:) withObject:foo];

If you're going to create a thread, use

NSThread* thread = [[NSThread alloc] init];
[object performSelector:@selector(method:)
               onThread:thread
             withObject:foo
          waitUntilDone:YES];
[thread release];
KennyTM
thanks for your reply. but this is not working. method not calling.
Allen
@Allen: What's your code?
KennyTM
Hi Kenny, you need to run a run-loop in the target thread so that the `performSelector:` input source is dealt with. So I don't think your code to work...
Yuji
@Kenny TM: your answer works perfectly. Thanks. I don't know why the poster couldn't get it to work and never accepted your answer, but it is correct. Thanks.
Digital Robot