Regularly refresh the background to execute an operation.

Source: Internet
Author: User

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

{

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.