• 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: NSTerminateLater and thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTerminateLater and thread


  • Subject: Re: NSTerminateLater and thread
  • From: Peter Lübke <email@hidden>
  • Date: Fri, 03 Jun 2011 20:26:15 +0200

Return NSTerminateCancel when applicationShouldTerminate calls ExecuteLogOutTask to be performed in a secondary thread.
At the end of your ExecuteLogOutTask method, call something like [myApplicationDelegate performSelectorOnMainThread: (logOutTaskDidFinish) withObject:nil waitUntilDone:NO].
Then, in logOutTaskDidFinish, call NSApplication's -terminate: method and set a flag indicating that ExecuteLogOutTask was already executed.
The next time applicationShouldTerminate is called, return NSTerminateNow if this flag is has been set so ExecuteLogOutTask is not called forever.


Cheers,
Peter


Am 03.06.2011 um 13:49 schrieb Leonardo:

I would like my application executes a given task before the log-out.
I almost succeeded but since this task could take a few minutes and since I
have to launch it on a separated thread (so the user could stop it), I am
getting some trouble.


In the applicationShouldTerminate method, I know that the Quit has been
invoked by the log-out thanks to the NSWorkspaceWillPowerOffNotification
So from within applicationShouldTerminate I invoke:
[self ExecuteLogOutTask];
return NSTerminateLater;
In this case the task gets executed properly but the user cannot cancel it.
The application looks unresponsive to the user.


So I tried:
[NSApplication detachDrawingThread:@selector(ExecuteLogOutTask)
toTarget:self withObject:nil];
return NSTerminateLater;
But I get a dialog saying:
You haven't been logged out because the application MyAppLogOut failed
to quit. Try logging out again....
And the ExecuteLogOutTask has not been called at all.


If I return NSTerminateCancel I cancel the whole log-out, which is not what
the user expects.


So how to manage this case?


Regards -- Leonardo

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: NSTerminateLater and thread
      • From: Kyle Sluder <email@hidden>
References: 
 >NSTerminateLater and thread (From: Leonardo <email@hidden>)

  • Prev by Date: Re: OS + iOS best practice
  • Next by Date: Re: OS + iOS best practice
  • Previous by thread: NSTerminateLater and thread
  • Next by thread: Re: NSTerminateLater and thread
  • Index(es):
    • Date
    • Thread