I have tons of [WebMethod]
in whole application and I want all my [WebMethod]
to be async. I decorated all my[WebMethod]
signatures with async and await keywords and then I run my app. It didn't work out as expected. Let say I have following code
Code Behind
[WebMethod]
public static async Task<List<XXX>> GetXXX()
{
return await new BusinessLogic().GetXXX().ConfigureAwait(false);
}
Business Layer
internal async Task<List<XXX>> GetXXX()
{
var obj = await objDAL.GetXXX().ConfigureAwait(false);
List<XXX> listDO = new List<XXX>();
foreach (var item in obj)
{
listDO.Add(new Countries
{
XXXName = item.name,
XXXID = item.id
});
}
return listDO;
objDAL.GetXXX
internal async Task<List<tblXXX>> GetXXX()
{
using (ABCEntities ctx = new ABCEntities())
{
return await ctx.tblXXX.ToListAsync().ConfigureAwait(false);
}
}
I have put debuggers in the whole path the code above come to return await ctx.tblXXX.ToListAsync();
and then the debugger loses control and the system became non-responsive.
I have found old solutions that doesn't use the power of async
and await
.
Question is how I can make my WebMethod Function asyc
.
Thanks
Task.Run
just this would work:return await new BusinessLogic().GetXXX();
– CounterscarpConfigureAwait(false)
to every await function does the job whenever the page is loaded for the first time, but when the page is requested again the client never gets the page and client remains in continuous wait. – Slider