Make WebMethod Async Webform

ぐ巨炮叔叔 提交于 2019-12-12 17:03:49

问题


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

来源:https://stackoverflow.com/questions/41934142/make-webmethod-async-webform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!