I have a loop that iterates 1 million times doing some calculations on a dataSet.
To show the progress of these calculations, I'd like to display the dataSet in an NSView periodically, say, every 10,000 loop iterations, then pause for 1 second so I can see the dataSet displayed in its current state.
for(j=0; j<1000000; j++)
{
...do some calculations on dataSet
if(j%10000 == 0){
[myView display] //[myView drawRect:] will show current state of dataSet
}
... pause for a second to see the dataSet in myView
}
So in this case I want 10 display updates, roughly 1 every second.
I've tried all sorts of ways, from using NSTimers to [NSThread sleepForTimeInterval], but so far I am only seeing the view updated after the loop has finished.
It doesn't matter if the thread/UI is blocked, as it's only to visualize my own calculations.
For sleep
usleep(useconds_t)
example for one second
usleep(1000000);