What is the best place to start a new thread? Should I create it in the Application Delegate, or can I start it from any other class for example a singleton?
Thanks for your help
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
if you’re joining the thread, then you will typically want to create the thread local (or accessible to) the creation site, or in the same object’s implementation. you’ll usually join or use a task based interface when you want execution of the current thread to block until the threads/tasks complete.
if detaching (likely if you
allocanNSThreador use adetach...call), then it may be created wherever it makes the most sense in your program’s flow.That means you should favor ‘local’ as opposed to centralized in both cases.
If you use a task based interface (e.g.
NSOperation), then you may need to centralize some things so many clients may reach an operation queue (as an example).extracting detail from the comments: if you create a detached thread to interact with a server, then it is likely a good idea to create the thread in your implementation which interacts with the server, or the client code that interacts with those implementations. The app delegate is not a good choice when the cause/effect does not need to be centralized.