How to check the number of pending events in the application event queue?
How to check the number of pending events in the application event queue?
- Subject: How to check the number of pending events in the application event queue?
- From: "Oleg Krupnov" <email@hidden>
- Date: Mon, 27 Oct 2008 14:54:52 +0200
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?
_______________________________________________
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