When we normally call a service method our code is executing sequentially ans it waits for the response returned by service and code execution is blocked, when we use Async methods, our code does not blocks and continues its execution and services fires an event when it returns response.
If i have called service synchronously:
var result = ReportClientObj.GetUserCoordinatesReport(searchParams);
if(result == null) // this line will not ewxecute until above line of code executes and completes
{
// do something
}
if i use async code execution will not stop:
var result = ReportClientObj.GetUserCoordinatesReportAsync(searchParams);
if(result == null) // this line will execute and will not wait for above call to complete due to asynshronous call and this will bang
{
// do something
}
For doing above thing in Async we have to use its Completed event
Register it's event:
reportClient.GetUserCoordinatesReportCompleted += reportClient_GetUserCoordinatesReportCompleted;
and then catch the comleted event, use its reponse:
void reportClient_GetUserCoordinatesReportCompleted(object sender, GetUserCoordinatesReportCompletedEventArgs e)
{
// Use Result here
var Result = e.Result;
if(Result !=null)
{
// do something
}
}
See here :
http://msdn.microsoft.com/en-us/library/ms730059%28v=vs.110%29.aspx
http://www.codeguru.com/columns/experts/building-and-consuming-async-wcf-services-in-.net-framework-4.5.htm