• 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: What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform)


  • Subject: Re: What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform)
  • From: 尹佳冀 <email@hidden>
  • Date: Mon, 04 Feb 2013 15:58:50 +0800

Thanks Mike seem You are right, and I write like this

[self performSelector:@selector(doTheThing) withObject:nil afterDelay:0.5];
it can work correctly.

And thanks for your suggestion

2013/2/3 Mike Abdullah <email@hidden>

>
> On 3 Feb 2013, at 07:41, 尹佳冀 <email@hidden> wrote:
>
> > Hi All
> >
> > Does anyone can know what the difference between [NSOperationQueue
> > currentQueue] and
> > performSelectorOnMainThread, If I do some work use operation
> > on [NSOperationQueue mainQueue], the UI will not hang up, but if i
> > use performSelectorOnMainThread the UI will hang up
> >
> > - (void) doTheThing
> >
> > {
> >
> > //Do do some work about 9~20 s
> >
> > }
> >
> >
> >       [self showIndicatorWithString:NSLocalizedString(@"Doing...", nil)];
> > // is a MBProgreessHUD, add a view then use a animation to show
> >
> >        //Case 4 not hang up, HUD show and can refresh, but the screen
> > cannot response user's touch
> >
> >        NSInvocationOperation *operation = [[NSInvocationOperation alloc]
> > initWithTarget:self
> >
> >
> >    selector:@selector(doTheThing)
> >
> >
> >      object:nil];
> >
> >        [[NSOperationQueue mainQueue] addOperation:operation];
> This causes -doTheThing to run on the main thread, a little later than now
>
> >
> >        //Case 2 hang up, HUD not show
> >
> >        //[self doTheThing];
> This executes -doTheThing immediately, on whatever thread is the current
> one
>
> >        //Case 3 hang up, HUD not show
> >
> >        //[self performSelectorOnMainThread:@selector(doTheThing)
> > withObject:nil waitUntilDone:YES];
> This executes -doTheThing immediately, on the main thread
>
> >
> >        //Case 4 not hang up, HUD show and can refresh, but the screen
> > cannot response user's touch
> >
> >         NSInvocationOperation *operation = [[NSInvocationOperation alloc]
> > initWithTarget:self
> >
> >
> >    selector:@selector(doTheThing)
> >
> >
> >      object:nil];
> >
> >        [[NSOperationQueue currentQueue] addOperation:operation];
> All depends on what's the current queue at the moment. If this code is
> running on the main thread, it'll be the main queue. If this code is
> running as part of an operation on a queue, it'll be that queue. Otherwise,
> it's fairly undefined, and might well return nil, meaning your code never
> runs.
>
> It seems you need to take the time to learn a little about how
> multithreading works and should be used with Cocoa.
>
>


--
Fykec Yin
_______________________________________________

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


  • Follow-Ups:
    • Re: What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform)
      • From: Steve Sisak <email@hidden>
    • Re: What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform)
      • From: Kyle Sluder <email@hidden>
References: 
 >What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform) (From: 尹佳冀 <email@hidden>)
 >Re: What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform) (From: Mike Abdullah <email@hidden>)

  • Prev by Date: iOS 6.0 SDK UIApplicationInvalidInterfaceOrientation
  • Next by Date: Re: NSDocument packages and incremental writing using NSFileWrapper
  • Previous by thread: Re: What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform)
  • Next by thread: Re: What's the difference between [NSOperationQueue currentQueue] and performSelectorOnMainThread (iOS platform)
  • Index(es):
    • Date
    • Thread