NSTask
registers a private run-loop source to monitor the task in the run loop of the thread on which it's launched. If that thread doesn't continue to exist and run its run loop, then Cocoa can't notice that the task has terminated. If Cocoa doesn't notice it, then it can't post the notification to your observer(s).
If the only thing you're doing with -performSelectorInBackground:...
is invoking the -launch
method of the task, then the thread doesn't stick around nor run its run loop. (Similarly, the worker threads that service GCD queues can't be relied upon to keep existing or run their run loops.) You could invoke a more complicated method in the background which launches the task and then runs the run loop, but that shouldn't be necessary.
Are you sure that launching the task is taking any appreciable amount of time? It really shouldn't. NSTask
is designed so that tasks can be created, launched, and monitored on the main thread without making it unresponsive.