Question

I am not clear about what does waitUntilDone do, but I found this thread:

What is the significance of WaitUntilDOne in performSelectorOnMainThread?

which makes me a bit clear, however, if I perform some selector which makes NSURLConnection(which is asyncrhonous) and waitUntilDone set to YES, what will happen then? It will wait for the method to execute, but the method actually does some asynchronous operation(ie NSURLConnection), then what is the impact?

Thanks!

Was it helpful?

Solution

NSURLConnection is asynchronous. Your code runs on the main thread, and it makes delegate calls to you as the download progresses. You don't need to, and should not, run an NSURLConnection from a background thread.

If you DO have code that needs to run on a background thread, you can use the preformSelectorOnMainThread method to send messages from your worker thread to the main thread. One common reason to do this is that you can't update the UI from a background thread. You'd invoke a method to update the UI on the main thread.

The flag waitUntilDone controls what happens after the performSelectorOnMainThread call. If waitUntilDone is false, your background thread continues on with the next line without waiting for the code on the main thread to finish.

If waitUntilDone is true, your background thread will block until the main thread finishes performing the selector that you sent it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top