However, we didn't test whether to create an nstimer in the Child thread for latency. It should be okay.[Nstimer timerwithtimeinterval: Invocation: repeats.
Special implementation
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
Method to ensure successful calls in the main thread
// Nsobject_performselectorex.h
@ Interface nsobject (performselectorex)
-(Void) implements mselecw.mainthread :( SEL) aselector withobject :( ID) anargument afterdelay :( nstimeinterval) delay;
@ End
// Nsobject_performselectorex.m
# Import
"Nsobject_performselectorex.h"
@ Implementation nsobject (effecmselectorex)
-(Void) implements mselecw.mainthread :( SEL) aselector withobject :( ID) anargument afterdelay :( nstimeinterval) Delay
{
Nsmethodsignature * Sig = [self
Methodsignatureforselector: aselector];
If (! SIG)
{
Return;
}
Nsinvocation * invo = [nsinvocation
Invocationwithmethodsignature: SIG];
[Invo
Settarget: Self];
[Invo
Setselector: aselector];
[Invo
Setargument: & anargument atindex: 2];
[Invo
Retainarguments];
Nsmethodsignature * sigmt = [invo methodsignatureforselector: @ selector (performselector: withobject: afterdelay :)];
Nsinvocation * invomt = [nsinvocation
Invocationwithmethodsignature: sigmt];
[Invomt
Settarget: invo];
[Invomt
Setselector: @ selector (effecmselector: withobject: afterdelay :)];
Sel arg1 = @ selector (invoke );
Void * arg2 = nil;
Nstimeinterval arg3 = delay;
[Invomt
Setargument: & arg1 atindex: 2];
[Invomt
Setargument: & arg2 atindex: 3];
[Invomt
Setargument: & arg3 atindex: 4];
[Invomt
Retainarguments];
[Invomt
Performselectoronmainthread: @ selector (invoke)
Withobject: Nil
Waituntildone: No];
}
@ End