In a program I am working on I am performing a large amount of data crunching, and want to be able draw a custom NSView to represent the process visually.
The data crunching is processed off the main thread by using GCD (using dispatch_sync as the order needs to be preserved):
for (int i=0; i<iterations; i++) {
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Add a data crunching task to the queue!
});
}
When the processing is started I initialise a timer, which is used to ask the custom display to redraw at regular intervals (this timer is invalidated once all of the processing tasks are completed):
-(void)onTick:(NSTimer *)timer {
[_customView setNeedsDisplay:YES];
// Update some other UI object (labels etc.)
}
I have this working as expected, however the only problem I notice now is that if I do something like click and hold on a button on the same window, or begin dragging a slider while the process is going on, the redrawing of the custom view is prevented until I let go of the mouse!
Is there any way I can prevent this from happening, preferably without moving all of the controls onto a separate window!
yip the timer is on the runloop and while in the drag drop / tracking mode it doesnt get fired because the runloop isnt advanced for the common mode
add it to the modes needed:
edit: the runloop is basically apple’s while loop for dispatch ANY event to an app. and it filters the events it dispatches based on so called modes.