Simple detachThread example

From MobileMasteryApp/threading/01

long task that blocks UI

In this example, we use the Activity Indicator to indicate the UI response. As you can see, when we start the loop to run through 40,000.

blockUI

to make it start animating. However, on the emulator, you won’t see it moving because the current main thread will process the loop count. When it finishes, then it stops the animating. However, visually, you won’t see the indicator move at all.

Non blocking task

In this example, we detach a thread to do our long process for us. Thus, this spares the main thread of extra work. The main thread’s task is to update the UI and do little processing as possible. Leave the heavy lifting to separate threads.

Leave a Reply