Re: Wait for NSTask to finish
Re: Wait for NSTask to finish
- Subject: Re: Wait for NSTask to finish
- From: Shawn Erickson <email@hidden>
- Date: Wed, 16 Mar 2005 15:44:47 -0800
On Mar 16, 2005, at 12:07 PM, Rakka wrote:
On Mar 16, 2005, at 10:52 PM, Will Mason wrote:
Is there a way to wait for an NSTask (or a method I created) to
finish
before continuing like waitUntilExit, but doesn't cause my app to
hang/become unresponsive?
It seems that you want to wait for the NSTask to finish and not wait
around for the NSTask at the same time. Can you let your app continue
and respond to the NSTaskDidTerminateNotification when you receive it?
What behavior exactly are you looking for?
Thanks,
Will
I don't think I can use NSTaskDidTerminateNotification as after it's
done, the app goes on to run another command, if the user prefs are
set to do so. It looks a bit like this.
- (IBAction)executeBatchTasks:(id)sender
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchRPOn"])
{
[task waitUntilExit];
[self rp:nil];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchRCOn"])
{
[task waitUntilExit];
[self rc:nil];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchUPOn"])
{
[task waitUntilExit];
[self up:nil];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchCCOn"])
{
[task waitUntilExit];
[self cuc:nil];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"batchFETOn"])
{
[task waitUntilExit];
[self fet:nil];
}
}
Yuck :-)
Why not represent your tasks as objects (that contain knowledge on what
they do and how they do it), then add those tasks to an array in the
execution order needed, then have a a block of logic that walks this
array in order asking each object to do its thing.
To deal with the GUI blocking issues either have the logic that walks
the array run in its own thread or have this block on logic work by
listening for a finished event (or callback) from a prior task and once
received have it check for any additional tasks in the array, rinse,
lather, repeat.
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden