On 27 okt 2008, at 13.54, Oleg Krupnov wrote:
In my app I'd like to perform some background task without affecting the responsiveness of the UI. To avoid multi-threading, I just postpone the task to a moment when the user becomes and stays idle for a certain time. I call NSObject's performSelector: afterDelay: and then use CGEventSourceSecondsSinceLastEventType to check if the idleness period has elapsed. If not, I wait again the remaining time, else I begin performing the task. Also, because the background task is quite lengthy, I make the task poll periodically if the user has become active during the task, and in this case postpone the task's continuation again until the user becomes idle again. This solution seems to be quite good, but for one question : how do I check if there are pending events in the application's queue right at the moment of timer firing? This would work as a double-check that there are no pending tasks for the application (e.g. other periodic events of the app) that would always have to be done before the low-priority background task. I tried NSApplication's nextEventMatchingMask, but it blocks execution if there are no events, whereas I'd like it to return nil. Any other suggestions? _______________________________________________
Use a separate thread. ------------------------------------------------------ "Home is not where you are born, but where your heart finds peace" - Tommy Nordgren, "The dying old crone" [EMAIL PROTECTED] _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]