Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:41:28+00:00 2026-05-25T01:41:28+00:00

MyThreadRun method is invoked from MyMethod like this NSArray* args = [NSArray arrayWithObjects:arg1, target,

  • 0

MyThreadRun method is invoked from MyMethod like this

NSArray* args = [NSArray arrayWithObjects:arg1, target, NSStringFromSelector(mySelector), nil];
NSThread* mythread= [[[NSThread alloc] initWithTarget:self selector: @selector(MyThreadRun:) object:args] autorelease];
[MyThreadRun start];

In the end of MyThreadRun, I try to invoke a function in the class which has called MyMethod to initiate the thread to begin with, like this:

NSObject* callbackTarget = [args objectAtIndex:1];
NSString* selector = [args objectAtIndex:2];
[callbackTarget performSelector:NSSelectorFromString(selector) withObject:calculationResult afterDelay:0];

I have a break point on the method that selector is pointing at, and it is never hit.

If I hard code the method name, like this

[callbackTarget updateWithResult:calculationResult] 

it works fine.

What is there I need to know about performSelector?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:41:29+00:00Added an answer on May 25, 2026 at 1:41 am

    The context where performSelector:withObject:afterDelay: is getting invoked is the culprit. Here’s what’s going on.

    Some members of the performSelector… family, like this one, don’t perform the selector right away; they queue up an invocation on the current run loop, so that it happens after your fn returns, the next go-round of the run loop. According to apple: “Specifying a delay of 0 does not necessarily cause the selector to be performed immediately. The selector is still queued on the thread’s run loop and performed as soon as possible.”

    Normally this is fine and expected. But your code is calling it on a thread that you started manually… and such threads don’t keep their run loop going repeatedly the way the main thread does. They invoke the selector specified at creation once, and exit. So: your code queues up an invocation of your callback selector, but then the thread exits; and its run loop is thrown away without ever running… so your queued invocation never happens.

    What you probably need is performSelectorOnMainThread:withObject:waitUntilDone:, since you may want the callback to happen on the thread that invoked the MyMethod method in the first place, which is presumably the main thread.

    More generally, threading is very tricky stuff. I highly recommend checking out NSOperationQueue, NSBlockOperation, and related techniques – they can remove a great deal of the pain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What does it mean to move a object from one thread to another in
I can create a class which extends Thread and overrides the run method with
The Qt documentation for QThread says to create a class from QThread, and to
I'm having android surfaceView and in that I'm trying to add buttons to this.
I have a calculating thread function which invokes message function from other thread using
Is there any way for me to share a variable between two web workers?
I know that it is not possible to restart a used Java Thread object,
I am programming a game on android. I'm using a Thread while calling a
Can you spot the error in the code? tickets ends up going below 0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.