Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Sequential Tasks

Sequential Tasks
Thread Tools
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 14, 2001, 02:15 PM
 
Hello,

I am running into problems when trying to execute several NSTasks one at a time. Essentially I need each task to wait for its predecessor to terminate before launching. I have tried to use a notification (TaskDidTerminate) that sets a finished flag partnered with a thread-stalling loop between each task but it doesn't work (I think that the sleepUntilDate call is even blocking the Notification).

Is there any simple way to do this is or will I have to do something similar to what I am doing now just with the Notification occurring in a different thread? Which also brings me to my next question: How can I specify which Thread a Notification response is launched into? Is it the same thread as the one who registered the observer?

Thanks in advance,
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 14, 2001, 10:32 PM
 
Shortly after posting this I did find the "waitUntilExit" method of NSTask. I have been trying to use it but it is not fixing any of my problems. Does anyone know if leaving an un-emptied NSPipe and its associated NSFileHandle will cease to allow the task to properly exit?

Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 15, 2001, 02:42 AM
 
Shortly after posting this I did find the "waitUntilExit" method of NSTask. I have been trying to use it but it is not fixing any of my problems. Does anyone know if leaving an un-emptied NSPipe and its associated NSFileHandle will cease to allow the task to properly exit?

Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Aug 15, 2001, 01:38 PM
 
Note that you can only use each NSTask instance once. And notifications are received in the same thread that they are posted, I thin, and you can't make them occur in other threads.
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 15, 2001, 02:05 PM
 
I read something in the Apple Developer documentation recently that said you can only call an NSTask once and that any subsequent calls will produce an error. Does anyone know if this means you can only call one instance once in each launch of your program or does it means something about having to release and re-instantiate the task each time?

If I can only use one task once, I guess I will have to find a different way of running sub-programs. Does anyone know if the security framework will let you launch a program without security and then go on to launch several tasks?

Thanks for any help,
Jeff.

[ 08-15-2001: Message edited by: Apocalypse ]
Spectral Class
"Shedding Light on Innovation"
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Aug 15, 2001, 03:10 PM
 
Originally posted by Apocalypse:
<STRONG>If I can only use one task once, I guess I will have to find a different way of running sub-programs. Does anyone know if the security framework will let you launch a program without security and then go on to launch several tasks?</STRONG>
What the documentation actually says is:
An NSTask can only be run once. Subsequent attempts to run an NSTask will raise an error.

You can definitely create more than one instance of an NSTask, otherwise what would the point of NSPipe be?

Security.framework is for authorization, nothing else. There are POSIX APIs for executing other processes should you need them, but NSTask is fine.

If you had played around before asking, you would easily find this to be the case.
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 15, 2001, 09:17 PM
 
I have played around with it but I am still getting problems trying to run multiple sequential tasks. It seems as though the first task locks the file so the second task doesn't want to use it. Does anyone know why this problem could be happening?

Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 16, 2001, 01:09 AM
 
Well, I found an application I wrote a few months back which does allow sequential calls to NSTask objects so I know that can't be the problem. Still, though, after days (several hours each day for the past 3) I still can't fix the problem. I even set my program to wait for a button to be clicked between each call and still I get this problem.

More about the problem:
I call one task that creates a file.
When the second task launches to work with the file, I get a crash claiming that the file is still in use.

Can anyone think of anything?

Thanks,
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:25 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2