A blog today on GCD: http://blog.devtang.com/blog/2012/02/22/use-gcd/
Set a timer in the main thread to regularly execute an operation.
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions
{
[Self
Startatimer];
}
-(Void) startatimer {
[Nstimer
Scheduledtimerwithtimeinterval: 1.0
Target: Self
Selector: @ selector (getnewsession :)
Userinfo: Nil
Repeats: Yes]; // This is the main thread.
}
-(Void) getnewsession :( nstimer *) thetimer {
[Self
Performselectorinbackground: @ selector (didnewsession)
Withobject: Nil];
}
-(Void) didnewsession
{
// A new thread is set for execution.
@ Autoreleasepool {
Dlog (@ "timer get new seesion ");
// If you want to update the UI of the main thread, execute this
[Self
Performselecw.mainthread: @ selector (refreshui)
Withobject: Nil
Waituntildone: Yes];
}
}
-(Void) refreshui
{
}