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 6805495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:35:36+00:00 2026-05-26T19:35:36+00:00

I want to launch a daemon on new thread, to my program doesn’t lock

  • 0

I want to launch a daemon on new thread, to my program doesn’t lock up while waiting for input from the daemon, but I need a way for the main program to get information back from the daemon. I’ve used NSThread to fire off a new thread, but I don’t see how to use a delegate with NSThread.

For more context, I’m working on a custom patch for Quartz Composer that will receive data from the network. The idea is that a second thread could run the daemon, and on each frame, I’d grab the new data from an ivar set by a delegate method when the daemon thread received new data.. all the while, the composition runs along with no interruption.

Can I do this with NSThread? Is there a better way I should be looking at?

  • 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-26T19:35:37+00:00Added an answer on May 26, 2026 at 7:35 pm

    Edit: If you want the delegate callbacks to occur on the main thread, use this pattern:
    [delegate performSelectorOnMainThread:@selector(threadDidSomething:) withObject:self waitUntilDone:NO]

    Here you go. I believe this is self-explanatory, but if not, just let me know. Please note: I just wrote this code based on the API, but have not tested it, so take caution.

    @protocol ThreadLogicContainerDelegate <NSObject>
    - (void)threadLogicContainerDidStart:(ThreadLogicContainer*)theThreadLogicContainer;
    - (void)threadLogicContainerDidFinish:(ThreadLogicContainer*)theThreadLogicContainer;
    @end
    
    @interface ThreadLogicContainer
    
    - (void)doWorkWithDelegate:(id<ThreadLogicContainerDelegate>)delegate;
    
    @end
    
    @implementation ThreadLogicContainer
    
    - (void)doWorkWithDelegate:(id<ThreadLogicContainerDelegate>)delegate
    {
        @autoreleasepool
        {
            [delegate threadLogicContainerDidStart:self];
    
            // do work
    
            [delegate threadLogicContainerDidFinish:self];
        }
    }
    
    @end
    
    
    @interface MyDelegate <ThreadLogicContainerDelegate>
    @end
    
    @implementation MyDelegate
    - (void)threadLogicContainerDidStart:(ThreadLogicContainer*)theThreadLogicContainer
    {}
    - (void)threadLogicContainerDidFinish:(ThreadLogicContainer*)theThreadLogicContainer
    {}
    @end
    

    Sample usage:

    ThreadLogicContainer* threadLogicContainer = [ThreadLogicContainer new];
    [NSThread detachNewThreadSelector:@selector(doWorkWithDelegate:)
                             toTarget:threadLogicContainer
                            withObject:myDelegate];
    

    reference: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html

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

Sidebar

Related Questions

I want to launch a file(a document) from a Java program and phase the
I want to launch an app on OSX from a script. I need to
i want to launch an intent from android website what code do i need
I've making an app and I want to launch a new activity from a
I have a ClickOnce deployed application I want to launch from VBScript, similar to
I want to be able to launch a Java server process from an existing
I want to create a simple bash script to launch a Java program on
I want to launch a specif application. I know how to do Intents but
I want to launch an Activity with a webView as its content from current
I want to launch the maps application from my mobile website. How can I

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.