时间:2019-03-17 标签:c#asyncawaitimplementation

发布于 2024-10-16 00:54:31 字数 339 浏览 7 评论 0原文

我对 C# 即将推出的 async/await 功能的设计有一些疑问。

  1. 将新机制附加到 Task 的便利性
  2. 我认为最好使用 async 代替 wait 关键字。 例如: var result = async GetResultAsync();
  3. 使用 async 取消正在进行的异步操作的机制 token 并不像我想象的那么优雅。

Async/away 是一个很棒的功能,但我认为它的设计不如 LINQ。另外,我觉得设计团队对当前的设计非常满意;并且可能不会考虑社区反馈。

你怎么认为?

I have some doubts about the design of C#'s upcoming async/await feature.

  1. The convenience of attaching the new mechanism to Task<T>
  2. I think is better to use async substituting the await keyword.
    For expaple: var result = async GetResultAsync();
  3. The mechanism to cancel a ongoing async operation using a
    token is not as elegant as I feel it could be.

Async/away is a great feature, but I think it's not as well designed as LINQ. Also, I feel the desing team is dangerously pleased with the current design; and might not take community feedback into account.

What do you think?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

农村范ル 2024-10-23 00:54:31

在您尝试自己完成这项工作之前,此类设计决策往往没有什么意义。您的任务:编写异步代码并让它在您想要的时候停止。您的限制:您不能使用 Thread.Abort() 并且永远不会导致死锁。

These kind of design decisions tend to make little sense until you've tried to make this work yourself. Your assignment: write asynchronous code and make it stop whenever you want to. Your constraints: you cannot use Thread.Abort() and can never cause deadlock.

本王不退位尔等都是臣 2024-10-23 00:54:31

Async/away 是一个很棒的功能,但我认为它的设计不如 LINQ。

与 LINQ 的设计过程相比,您认为设计过程的哪些方面存在缺陷?

此外,我觉得设计团队对当前的设计非常满意;并且可能不会考虑社区反馈。

是什么给你这样的印象?一段时间以来,我们一直在邀请社区提供反馈。它并没有被忽视。

你觉得怎么样?

我认为这是一个讨论问题而不是工程问题。您确定这是回答该问题的正确网站吗?

Async/away is a great feature, but I think it's not as well designed as LINQ.

What aspects of the design process do you feel are deficient compared to the design process for LINQ?

Also, I feel the design team is dangerously pleased with the current design; and might not take community feedback into account.

What gives you that impression? We've been inviting community feedback for quite some time now. It is not being ignored.

What do you think?

I think this is a discussion question and not an engineering question. Are you sure this is the right site for this question?

葬心 2024-10-23 00:54:31
  1. 他们已经在 TaskTask 上投入了大量的工作,其设计就是为了完美地适应这种情况。我发现这非常方便,因为我确切地知道对任务的期望 - 以前使用过它 - 而且我认为很多其他开发人员也会有这种感觉。在我看来,这比引入新的东西要好得多——而且我什至不确定有什么不同可以使新类型更能胜任这项任务。您有什么具体的想法吗?

  2. 我认为您错过了 async 关键字的用途。它用于标记将(部分)异步执行的方法(当您使用 await 关键字时)。编译器需要知道哪些方法要“执行魔法”;它不会将方法“转换”为异步执行。为此,您应该使用 ThreadPool.QueueUserWorkItem.

  3. 我无法对此发表评论。您认为更优雅的解决方案是什么?我相信,如果您与 Microsoft 分享反馈,Microsoft 会考虑您的反馈。

  1. They have already invested a lot of work into Task and Task<T>, which is designed to perfectly fit this situation. I find this very convenient, because I precisely know what to expect of a Task - having it used previously - and I think a lot of other developers will also feel that way. In my opinion it's a lot better than introducing something new - and I'm not even sure what could be different that would make a new type more up to the task. Do you have any concrete ideas?

  2. I think that you're missing the purpose of the async keyword. It is used to mark methods that will be (partially) executed asynchronously (when you use the await keyword). It is required for the compiler to know which methods to "perform magic on"; it doesn't "convert" a method to be executed asynchronously. For that you should use ThreadPool.QueueUserWorkItem.

  3. I can't really comment on this. What would be a more elegant solution in your opinion? I'm sure Microsoft will take your feedback into consideration if you share it with them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文