纤维VS异步等待 [英] Fibers vs async await

查看:165
本文介绍了纤维VS异步等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入其中,开发者大量使用纤维的C#项目。这个项目之前,我还没有听说过他们和previously使用异步的await 主题的BackgroundWorker s到我的多任务操作。今天,我问他们为什么使用光纤和主要开发人员说,这对他来说更容易调试。这意味着他知道某个特定函数有来自哪个线程,甚至可能更高访问堆栈中的变量

我想知道什么是使用的优点和缺点光纤 s和使用新的异步的await 和使用秒。

PS:我们正在使用.NET 4.5


解决方案

  

我问他们为什么,他们用纤维和主要开发者说
  它更容易为他调试。这意味着他知道哪个线程
  特定功能有来自,甚至可能访问的变量
  在堆栈中较高的。


这听起来完全奇特。当使用任务并行库比默认的其他自定义调度 ThreadPoolTask​​Scheduler ,你可以,你自己,决定如何您的任务获得计划(它不一定是对新的线程)。 异步等待,另一方面为您提供做异步IO的一种便捷方式。 VS给你调试异步code。使用就好像它是同步执行的能力。

为了使用纤维,一个人必须要调用非托管的API,因为.NET不提供在任何BCL托管的包装。 即使纤维的文档说清楚有没有一个明确的优势,使用它们


  

在一般情况下,的纤维不提供超过一个精心设计的优点
  多线程应用程序。
然而,使用的纤维可以更容易地
  这被设计来安排自己的线程端口的应用程序。




  

我想知道有什么优点和使用的优缺点
  纤维VS使用新的异步等待和使用线程。


使用异步等待给你做的IO约束异步工作,而感觉就像你在同步执行的益处。在任务并行库提供专用线程调度工作的一个简单的方法,是其中线程池中的线程或新主题,同时让你挂接到其中安排这些单位的机理工作的。我实在看不出有什么优势,在今天使用的纤维,与所有的框架所提供的。

我觉得你应该告诉你的主要开发者使用任务并行库做多线程和异步IO工作的一些阅读异步-await分别为。我认为这将让生活更容易为大家。

I'm joining a C# project in which the developers are heavily using Fibers. Before this project I haven't even heard of them and previously used async await and Threads and BackgroundWorkers to my multitasking operations. Today 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.

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

PS: We're using .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.

That sounds outright peculiar. When using the Task Parallel Library with custom schedulers other than the default ThreadPoolTaskScheduler, you can, yourself, decide how your tasks get scheduled (and it isn't necessarily on new threads). async-await on the other hand provides you a convenient way of doing asynchronous IO. VS gives you the ability to debug asynchronous code using as if it were executing synchronously.

In order to use fibers, one would have to invoke unmanaged API's, as .NET doesn't offer any managed wrappers in the 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.

Using async-await give you the benefit of doing IO bound asynchronous work while feeling like you're executing synchronously. The Task Parallel Library provides an easy way of scheduling work on dedicated threads, be them thread-pool threads or new threads, while allowing you to hook into the mechanism which schedule those units of work. I really see no advantage in using fibers today, with all the framework has to offer.

I think you should tell your main-developer to do some reading on multi-threaded and asynchronous IO work using the Task Parallel Library and async-await, respectively. I think it would make life easier for all of you.

这篇关于纤维VS异步等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆