Reputation: 23868
In the following method I'm getting the warning: This async method lacks 'await' operators and will run synchronously
. Where can I use await
in this mehod? Note: This method is returning a simple static View without interacting with a Database etc.
public class TestViewComponent : ViewComponent
{
public async Task<IViewComponentResult> InvokeAsync()
{
return View();
}
}
Upvotes: 8
Views: 5454
Reputation: 457057
Since you have no asynchronous work to do, you could remove the async
qualifier and just return Task.FromResult
:
public Task<IViewComponentResult> InvokeAsync()
{
return Task.FromResult<IViewComponentResult>(View());
}
Alternatively, you could just ignore the warning (i.e., turn it off with a #pragma
).
Upvotes: 17