Re: How to check the number of pending events in the application event queue?
Re: How to check the number of pending events in the application event queue?
- Subject: Re: How to check the number of pending events in the application event queue?
- From: Tommy Nordgren <email@hidden>
- Date: Mon, 27 Oct 2008 14:01:46 +0100
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@hidden
_______________________________________________
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