Why should a void method be async to be able to await?

Assume I have a method that has void return type and that I need to await on an operation in this method.

public void someOperation()
{
    //dostuff
    var res = await someOtherOperation();
    //do some other stuff that needs res.
}

When I tried to compile this code I got the error saying someOperation has to be declare async. I don't understand why. I understand why it would if the method had a return value, but not here when it's void. or even in the case when the awaiting operation has no effect on the return value of method.
This has already been asked as a part of this question but I didn't find the answer I was looking for. This guy merely mentions:

The async keyword enables the await keyword. So any method using await must be marked async.

  • First of all, I'm not sure what it means that async keyword enables await keyword.
  • And secondly, restating my question, I'm not sure why it is required?
Jon Skeet
people
quotationmark

I don't understand why.

Because you need to tell the compiler that you're trying to write an async method. That's exactly what the document you're quoting means.

The compiler could infer that from whether or not your method includes any await expressions - but that would mean you could comment out one line of a method and the whole method's behaviour would radically change. (Think about exception handling, for example...)

It also improves readability - it means anyone reading your code knows this is an async method right from the start.

So basically, the answers are:

  • You need to because the language specification requires you to. The compiler is implementing the language specification.
  • The language specification requires you to because it reduces the element of surprise.

people

See more on this question at Stackoverflow