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

  • SEARCH
  • Home
  • 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 6735203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:58:54+00:00 2026-05-26T10:58:54+00:00

I am writing a Foundation Tool. I have to do the threading to separate

  • 0

I am writing a Foundation Tool. I have to do the threading to separate to different ongoing tasks.

I tried to do threading but it was continuously getting crashed. And finally I figured out the reason that, I need to have my own runloop running.

Can some one help with with some simple example? I tried following code but it does not work. Every time I run it i crashes with Exception? How can I run a thread in Foundation tool?

@interface MyClass : NSObject
{
}
-(void) doSomething;
@end

@implementation MyClass
-(void) RunProcess:
{
    printf("test");  
}
-(void) doSomething:
{
    [NSThread detachNewThreadSelector: @selector(RunProcess:) toTarget:self withObject: nil];  
}
@end

int main(void)
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    MyClass *myObj = [[MyClass alloc] init],
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 myObj selector:@selector(doSomething:) userInfo:nil repeats:NO];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    [[NSRunLoop currentRunLoop] run];

    [pool drain];
    return 0;
}
  • 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-26T10:58:55+00:00Added an answer on May 26, 2026 at 10:58 am
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 myObj 
            selector:@selector(doSomething:) userInfo:nil repeats:NO];
    

    Notice your selector is -doSomething: with a colon and argument, yet your method as implemented is -doSomething, without a colon and argument. Actually, your declaration of the method (-doSomething) doesn’t match the implementation (-doSomething:). It’s not clear if that’s just a mistake here in typing your example, or whether that’s actually in your code. What is the exception that’s raised?

    If this mistake is in your code, then the timer ends up trying to send a message to your MyClass object that it won’t understand, which raises an exception, most likely.

    You should likely change the method your timer is set to fire to the following, as recommended in the documentation for +scheduledTimerWithTimeInterval:target:selector:userInfo:repeats::

    @interface MyClass : NSObject {
    
    }
    -(void)doSomething:(NSTimer *)timer;
    @end
    
    @implementation MyClass
    
    -(void)doSomething:(NSTimer *)timer {
          [NSThread detachNewThreadSelector:@selector(RunProcess:)
           toTarget:self withObject:nil];  
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m writing an CI application that has to have authentication and preferably different roles
I'm writing an ASP.net application that uses Windows Identity Foundation. My ASP.net application uses
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Am getting errors in this piece of code; I have placed the error messages
The new Web API stuff looks great. I will be re-writing the foundation of
Best practices for writing long running custom activities for Workflow Foundation (3.0/3.5) suggest that
For my own personal amusement, I'm writing what I hope will be the foundation
I am new to Documentum, I have to upgrade one code from Documentum foundation
I'm a noob at programming, but I'm starting to learn. I'm writing for iPhone,
I'm writing an application that needs to connect to the Team Foundation Server, and

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.