minimalist implementation of async await
async-await, asynchronous, c#
Solution
You make a good case - and I believe that the compiler only truly needs the "await" keyword. I don't think that it cares about the "async" modifier.
However, the fact that the compiler insists that you mark your methods with the "async" modifier is a good thing - it allows you to check whether a method will run synchronously/asynchronously without having to dig into its implementation. It also tells you whether you'll have to/be able to `await` it. I believe these were the reasons to enforce the use of both keywords, and not just one.
A similar case would be: why do you need to mark interface implementation methods with the "public" access modifier, even though it cannot be private/internal/protected/protected internal? Seems redundant right? It does, however, increase readability.
Problem
Trying to understanding why .NET implemented async-await the way they did. When changing a simple section of code to use async-await, it seems like the least required effort is to mark both the calling and the called methods with async-await directives: ``` private async void OnGuiClick(object sender, EventArgs args) { textBox1.Text = await Work(); } private async Task<string> Work() { await Task.Delay(2000); return "Result"; } ``` Why does .NET insist on both? i.e. It would have been nice to specify with a single keyword, that an expression must immediately be evaluated asynchronously on a worker thread - while the calling GUI thread is freed to perform other tasks, but will be hooked up again to execute the remaining code once the worker thread is done. Is there a simpler or better way of assigning a worker thread to process the Work method, and then automatically (without needing to resort to Invoke(...)) ensure the same calling GUI thread processes the result? Why not something like this: ``` private void OnGuiClick(object sender, EventArgs args) { textBox1.Text = <'some async directive'> Work(); } private string Work() { Thread.Sleep(2000); return "Result"; } ``` (The MSDN documentation states that the compiler will execute code synchronously if the target does not contain an await statement - but then what's the point? - Surely the await async keywords are only intended for asynchronous usage. Then why make it so complicated, instead of using a single directive?)