Wednesday, June 15, 2011

Synchronous & Asynchronous Methods

It is so important to know whether a method call is synchronous or asynchronous.

Firstly i'll explain the difference between the two;

Synchronous methods, complete its execution and then returns the control back to where it was called from and the process further continues.

Whereas asynchronous methods when called they get started in their own separate thread, and run independently without affecting the main process thread.

Most of the methods are synchronous as they are easy to handle and operate with, but a few methods like webcomponents are asynchronous. For eg. downloading something while application is running is asynchronous method, also logically it should be so, since the data to be downloaded can be large or depending on network may take longer time, hence the main thread cannot stop for so long.