Doing a task that needs to update the screen
<p>Imagine I have a spinner that I have to enable while something relatively heavy is being done and then deactivate the spinner after the task is done.</p>

<p>If I do:</p>

<pre><code>[mySpinner startAnimating];
[self doSomethingHeavy];
[mySpinner stopAnimating];
</code></pre>

<p>I will never see the spinner running, because doSomethingHeavy will lock the thread and never let the spinner show.</p>

<p>I have tried to fire a new queue on the main thread using Grand Central Dispatch for the spinner and in another try for the task, but the results are the same. No spinner running.</p>

<p>The only way to make it work is to fire the method with a delay, using </p>

<pre><code>[self performSelector:@selector(doSomethingHeavy) withObject:nil afterDelay:0.02];
</code></pre>

<p>but this sounds more like a hack and if I put <strong>[mySpinner stopAnimating]</strong> after that line, it will probably stop the spinner before the task is done.</p>

<p>This is not just valid for the spinner but for any task that that needs screen update.</p>
