• 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: Anything like -[performBlockOnMainThread:]?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Anything like -[performBlockOnMainThread:]?


  • Subject: Re: Anything like -[performBlockOnMainThread:]?
  • From: Gerd Knops <email@hidden>
  • Date: Mon, 15 Mar 2010 17:55:00 -0500

On Mar 15, 2010, at 4:32 PM, Rick Mann wrote:

> Instead of passing my operation a target and selector, is there any way I can just pass it a block, but then have it execute that block on the main thread?

Note that the methods listed so far will cause a deadlock if called from the main thread.

For the non-parameters form I use the below as a category on NSObject, should be trivial to add arguments.

Gerd

- (void)runOnMainQueue:(void (^)(void))aBlock {

	//
	// Execute *aBlock* on the main queue/thread.
	//
	// # Parameters
	// aBlock
	// :	The block to be executed.
	//
	// # Discussion
	// When called from the main queue the block is executed immediately.
	// Otherwise the block will be scheduled for execution on the main queue,
	// the method will return after the block was executed.
	//
	if(dispatch_get_current_queue()==dispatch_get_main_queue())
	{
		aBlock();
	}
	else
	{
		dispatch_sync(dispatch_get_main_queue(),aBlock);
	}
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Anything like -[performBlockOnMainThread:]? (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Private ivars, not marked as IBOutlet, visible in IB
  • Next by Date: Re: Private ivars, not marked as IBOutlet, visible in IB
  • Previous by thread: Re: Anything like -[performBlockOnMainThread:]?
  • Next by thread: NSTrackingArea Problem
  • Index(es):
    • Date
    • Thread