Reputation: 30102
Is it best to send a synchronous or an asynchronous request?
I'm sending a request to a server, asking for a list of files, which I would like the user to choose from.
Upvotes: 1
Views: 1856
Reputation:
You'd want to use asynchronous calls when you're calling from the Main Thread. Otherwise, the whole user interface will become unresponsive (i.e: freeze) until the server responds. (The user interface in maintained by the main thread).
You'd want to use synchronous calls when you're calling from another thread and you want it to wait until it has the response before continuing. If you've manually created a thread, calling asynchronous from this new thread would create a third thread.
Asynchronous means the "calling body" won't wait until the task is done.
Upvotes: 0
Reputation: 14815
You should always use asynchronous requests as they do not block the thread they are called from. Instead they will call your delegate methods when the connection fails or succeeds. If you need to prevent the user from doing anything while the connection is running, use a HUD class like MBProgressHUD (check github).
Upvotes: 1
Reputation: 3619
Synchronous request does stop the application from any user action until it completes, because it runs in the main thread.
Asynchronous does not as it runs in other thread.
Upvotes: 3