• 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: Detecting if UI thread is running, and creating a UI thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting if UI thread is running, and creating a UI thread


  • Subject: Re: Detecting if UI thread is running, and creating a UI thread
  • From: Justin Armstrong <email@hidden>
  • Date: Fri, 02 Mar 2007 16:28:49 +0000


Hi Glenn,

Thanks for your help!

glenn andreas wrote:

On Mar 2, 2007, at 5:16 AM, Justin Armstrong wrote:

The problem is that we cannot assume the caller of CreateJob() is actually a Cocoa/Carbon app with a UI thread. If the caller is a command line app then there will be no UI thread to handle the event loop and respond to the button click events. So...

How can i determine if a UI thread is running?

There is no such thing as a "UI thread" - you've made some assumptions here that are going to get you stuck.


There are actually two different things going on here.

First, all UI needs to be done on the main thread, be it Carbon or Cocoa. There is always a main thread (so in Cocoa it's always safe to do performOnMainThread: et al). If you do UI from a non-main thread, it will crash sooner or later (with "sooner" being more likely).


By "UI thread" i just mean the thread which runs the event loop. This seems to be called the "main thread" in Mac documentation, so i'm wondering if this means that it is hardwired to be the first thread of the process. Obviously a standard Cocoa/Carbon app will run the event loop in its first thread. In the case of a Cocoa app the event loop is started by the call to NSApplicationMain() from the boilerplate main() function. What I'd like to know is if it is possible for a command line type program which has not started an event loop to spawn a second thread and then make that the "main thread". Is it just a case of calling NSApplicationMain in the new thread instead?



However, not all processes can do UI. By default, command line processes don't support UI (if you try, you'll get a window that is non-responsive), since command line processes are potentially run by things via ssh on remote machines (or in the middle of the night by cron when nobody is logged on).

Instead, in a command line process, you'll need to convert the process to one that communicates with the window server via TransformProcessType, though the better solution is to bundle it as a "real" application (i.e., in a bundle, with an Info.plist file)


Ok, perhaps in the case of a command line app, i will just fall back to a default action and rather than asking the user.
I will check for LSBackgroundOnly and not show a UI in that case.



Thanks, Justin _______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Detecting if UI thread is running, and creating a UI thread
      • From: glenn andreas <email@hidden>
    • Re: Detecting if UI thread is running, and creating a UI thread
      • From: James Bucanek <email@hidden>
References: 
 >Detecting if UI thread is running, and creating a UI thread (From: Justin Armstrong <email@hidden>)
 >Re: Detecting if UI thread is running, and creating a UI thread (From: glenn andreas <email@hidden>)

  • Prev by Date: Re: Unfathomable CIImage - Really get crazy about it
  • Next by Date: Re: Detecting if UI thread is running, and creating a UI thread
  • Previous by thread: Re: Detecting if UI thread is running, and creating a UI thread
  • Next by thread: Re: Detecting if UI thread is running, and creating a UI thread
  • Index(es):
    • Date
    • Thread