Ignore async without await compilation warning

后端 未结 2 1899
星月不相逢
星月不相逢 2021-02-10 11:19

I have a base controller with the following abstract method:

[HttpDelete]
public abstract Task Delete(int id);

In one

2条回答
  •  旧时难觅i
    2021-02-10 11:36

    Apart from ignoring the above warning, is there a better alternative (ie. changing the code above) so that this warning doesn't occur?

    The alternative is to remove the async modifier and use Task.FromResult to return a Task:

    public override Task Delete(int id)
    {
        return Task.FromResult(
                    ResponseMessage(Request.CreateResponse(
                                            HttpStatusCode.MethodNotAllowed,
                                            new NotSupportedException())));
    }
    

提交回复
热议问题