Using async/await and returning Task From ASP.NET Web API Methods

前端 未结 2 1238
花落未央
花落未央 2021-02-06 01:11

I have a Portable Class Library (PCL) method like this:

public async Task GetLineStatuses()
{
    HttpWebRequest request = (HttpWebRequest)WebReque         


        
2条回答
  •  名媛妹妹
    2021-02-06 02:08

    Async and await are perfectly acceptable in ASP.NET. Here's a Scott Handselman video demoing it: http://www.asp.net/vnext/overview/aspnet/async-and-await

    "Also would I have the same effect if I returned Task rather than Task?"

    Not really sure what you mean by this. The Task is like a container for the object, so a Task would contain your string result and a Task would contain your HttpResponseMessage result... Is that what you mean? I think either method is perfectly acceptable. If you just need the string, then go with that. No point in returning more than you need.

提交回复
热议问题