加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Fibres vs async等待

发布时间:2020-12-15 03:43:31 所属栏目:百科 来源:网络整理
导读:我加入了一个C#项目,其中开发人员大量使用 Fibers.在这个项目之前,我甚至没有听说过他们,以前使用异步等待和Threads和BackgroundWorkers进行多任务操作.今天我问他们为什么使用光纤,主要的开发者说他更容易调试.意思是他知道一个特定功能来自哪个线程,甚至可
我加入了一个C#项目,其中开发人员大量使用 Fibers.在这个项目之前,我甚至没有听说过他们,以前使用异步等待和Threads和BackgroundWorkers进行多任务操作.今天我问他们为什么使用光纤,主要的开发者说他更容易调试.意思是他知道一个特定功能来自哪个线程,甚至可以访问堆栈中更高的变量.

我想知道使用Fibres和使用新的异步等待和使用Threads有什么优点和缺点.

PS:我们正在使用.Net 4.5

解决方法

I was asking them why they used Fibers and the main developer said
that it’s easier for him to debug. Meaning he knows which thread a
particular function has come from and even could access the variables
higher in the stack.

这听起来很特别.当使用任务并行库与默认ThreadPoolTask??Scheduler以外的自定义调度程序时,您可以自己决定如何计划任务(并不一定在新线程上).异步等待另一方面为您提供了一种方便的异步IO方式. VS使您能够使用同步执行的异步代码调试功能.

为了使用光纤,人们必须调用非管理的API,因为.NET不会在BCL中提供任何托管包装器. Even the docs of fibers clearly say there isn’t a clear advantage to using them:

In general,fibers do not provide advantages over a well-designed
multithreaded application.
However,using fibers can make it easier to
port applications that were designed to schedule their own threads.

I was wondering what are the advantages and disadvantages of using
Fibers vs using the new async await and using Threads.

使用async-await可以让您在执行IO绑定的异步工作的同时感受到正在执行同步的好处.任务并行库提供了一种简单的方法来调度专用线程的工作,无论是线程池线程还是新线程,同时允许您挂接安排这些工作单元的机制.所有的框架都提供了,我真的看不到使用纤维的优势.

我想你应该告诉你的主要开发人员分别使用Task Parallel Library和async-await对多线程和异步IO工作进行一些阅读.我认为这样会使你们的生活更轻松.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读