• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using NSTimer to call the main thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSTimer to call the main thread


  • Subject: Re: Using NSTimer to call the main thread
  • From: "A.M." <email@hidden>
  • Date: Thu, 27 Mar 2003 14:03:04 -0500

That would not be a good idea since the message could be called by the other thread simultaneously and create a race condition. The solution is to use NSNotificationCenter which is great for this type of thing. Read the link below for info on using the NSNotificationCenter with threads.

http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/ ProgrammingTopics/Notifications/index.html#//apple_ref/doc/uid/10000043i

On Thursday, Mar 27, 2003, at 13:36 US/Eastern, email@hidden wrote:

wouldnt it be equally possible to pass a reference to the UI controller to the
secondary thread and call updateValueNow: directly?

On Thu, 27 Mar 2003 10:35:36 -0800 (PST), Peter Robinson wrote:


I am trying to communicate with the main thread in order to update
the user interface.

From my secondary thread, I can install a one-off NSTimer on the
run-loop of the main thread, like this:

NSTimer *timer = [NSTimer timerWithTimeInterval: 0
target: self selector: @selector(updateValueNow:)
userInfo: nil repeats: NO];

[mainRunLoop addTimer: timer forMode: NSDefaultRunLoopMode];

which seems to work well enough. But I am worried that it isn't
legal to install a timer on a run-loop from another thread. Can I do
this? If not, what is the simplest way to get code called on the
main thread? I am using 10.1.

Thanks,

Peter
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: <a
href="http://mail.canada.com/jump/http://www.lists.apple.com/mailman/ listinfo/cocoa-dev">http://www.lists.apple.com/mailman/listinfo/cocoa- dev</a>
Do not post admin requests to the list. They will be ignored.

__________________________________________________________
Get your FREE personalized e-mail at http://www.canada.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


><><><><><><><><><
AgentM
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Size of a bundle (or directory)
  • Next by Date: Re: Need advice: handling SQL DB based datasource for NSTableView
  • Previous by thread: Re: Using NSTimer to call the main thread
  • Next by thread: Re: Using NSTimer to call the main thread
  • Index(es):
    • Date
    • Thread