I have a JQuery AJAX call for ASP.NET WebMethod.
I understand the async: true
that allows the WebPage not to be locked until the function returns and therefore i set it to 'true'
.
The problem that i am facing is that the inner method GetVersionFromDataBase()
inside the GetVersion()
takes a long time until it finishes, and meanwhile the whole backend is locked (single threaded).
The user experience is that for the other user who are browsing the website, even on different pages, their screen is locked until the 'heavy' method returns.
How can i make the function GetVersionFromDataBase()
be in a different thread / tasks?
$.ajax({
type: "POST",
url: "Default.aspx/GetVersion",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (result) {
alert('the version is:' + result.d);
}
});
public partial class Default : System.Web.UI.Page
{
[WebMethod]
public string GetVersion()
{
string version = GetVersionFromDatabase(); // this is a heavy method freezes the program till it finishes
return version;
}
}