Should I use await with async Action method?

前端 未结 4 1682
春和景丽
春和景丽 2020-12-11 06:36

I need to implement an asynch Action in my Controller for a long running external API call.

Looking at some tutorials, I have implemented my method like this:

<
4条回答
  •  时光取名叫无心
    2020-12-11 06:52

    As the other person wrote you need an asynchronous action to await it, to make View() async wrap it in a Task.Run

    [AsyncTimeout(200)]
    public async Task DoAsync()
    {
        // Execute long running call.
        return await Task.Run(() => View());
    }
    

    Afterwards this method is mainly useful for calling from other async functions or callbacks.

提交回复
热议问题