I have a base controller with the following abstract method:
[HttpDelete]
public abstract Task<IHttpActionResult> Delete(int id);
In one particular controller, I don't want to implement deletion, so the method looks like this:
public override async Task<IHttpActionResult> Delete(int id)
{
return ResponseMessage(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, new NotSupportedException()));
}
Although the above code compiles, I get a warning:
This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
Apart from ignoring the above warning, is there a better alternative (ie. changing the code above) so that this warning doesn't occur?
EDIT
I change the line to:
return await Task.Run(() => ResponseMessage(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, new NotSupportedException())));
This removes the warning. However, is there a better solution?