Below is a code snippet in which I get data from a third-party API with async methods.
jQuery code:
function retrieveSummary() {
$.ajax({
type: "POST",
url: 'api/GetLeads',
dataType: "json",
async: true,
error: function (xhr, textStatus, thrownError) {
},
success: function (data) {
},
failure: function (data) {
}
});
}
C# Code with an async method in which the above JSON stuck, wrote comments.
[HttpPost]
[ActionName("GetLeads")]
public List<Leads> GetSummary()
{
List<Leads> list = new List<Leads>();
var result = RunAsync(publicKey, secretKey).Result;
var data = result.GetData();
// Process data and return but it stucks on below async method RunAsync in await line.
.
.
}
static async Task<Response> RunAsync(string publicKey, string secretKey)
{
Client client = new Client(publicKey, secretKey);
Request request = new Request()
{
Resource = Message.Resource
};
request.Filter(Message.Limit, limit)
.Filter("FromTS", String.Format("{0:s}", fromDate))
.Filter("ToTS", String.Format("{0:s}", toDate))
.Filter("ShowContactAlt", "true")
.Filter("ShowSubject", "true")
.Filter("MessageStatus", 3)
.Filter(Message.Offset, offSet);
// Ajax call stucks here.
return await client.GetAsync(request);
}