C# 5 async/await thread mechanics feel wrong?

后端 未结 3 1154
终归单人心
终归单人心 2021-02-05 22:10

Why have the calling thread walk into the async method until the inner \'await\'?

Isn\'t it cleaner to just spawn a thread as soon as an async method is called. That way

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 23:02

    I tend to like to know whether a method is going to execute code on 'my' thread or not.

    I think that is a peculiar desire, not really a good argument for/against any feature.

    The main point of async/await is that the code for starting an async op and handling the results can be kept into one method.

    Without it you are forced to break code that logically belongs together into 2 parts.

提交回复
热议问题