Detecting if UI thread is running, and creating a UI thread
Detecting if UI thread is running, and creating a UI thread
- Subject: Detecting if UI thread is running, and creating a UI thread
- From: Justin Armstrong <email@hidden>
- Date: Fri, 02 Mar 2007 11:16:19 +0000
Hi,
Apologies for the length of this message. I'm porting a library from
Windows to Mac. The library contains a function, call it "CreateJob()",
which returns when a video encoding job has been created or an error
occurs. This API cannot change as it is used by 3rd party apps. In
certain circumstances the server which does the actual encoding may be
too busy to accept a job and we want to display a non-modal dialog which
allows the user to either wait or cancel the job.
CreateJob() will be called from a non-UI thread.
If CreateJob() discovers the server is busy it brings up the dialog and
sits in a loop polling for either a message from the server saying it is
ready to accept the job, or a flag set by the UI thread as a result of
the cancel button being clicked. I have implemented this with Cocoa and
it seems to be working when called by Carbon and Cocoa apps.
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?
I would have expected [NSApp isRunning] to return NO if called from a
command line program that has never called [NSApp run]. However, once
NSApplicationLoad() has been called [NSApp isRunning] seems to always
return YES. Does anyone know why?
Is it possible to start another thread, and make that the UI thread?
Thanks!
Justin Armstrong
_______________________________________________
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