C# 为什么要使用 Windows 工作流?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/513657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:21:32  来源:igfitidea点击:

Why use Windows Workflow?

c#.networkflowworkflow-foundation

提问by DSO

What is the benefit of using Windows Workflow foundation (WF) versus rolling your own workflow framework?

使用 Windows 工作流基础 (WF) 与滚动您自己的工作流框架有什么好处?

From what I can tell, WF only provides a pretty bare-bones runtime engine, a bunch of classes, and a schema (XAML-based) for defining workflows. All the hard stuff such as persistence, providing a host process for the runtime, and implementing distributed workflows (across processes) is left up to you.

据我所知,WF 只提供了一个非常简单的运行时引擎、一堆类和一个用于定义工作流的模式(基于 XAML)。诸如持久性、为运行时提供宿主进程以及实现分布式工作流(跨进程)之类的所有难题都由您决定。

Plus there is a learning curve to using WF... if we created our own workflow framework we would simply leverage skills that all developers already have (C#, XML, SQL, etc).

另外,使用 WF 有一个学习曲线……如果我们创建自己的工作流框架,我们将简单地利用所有开发人员已经拥有的技能(C#、XML、SQL 等)。

I saw this blog from an MS evangelist which tries to explain why we should use WF:

我从一位 MS 布道者那里看到了这篇博客,它试图解释为什么我们应该使用 WF:

Why Workflow?...

为什么是工作流?...

IMO it doesn't do a good job of convincing because it just states that it helps "developer productivity", while admitting that developers could roll their own.

IMO 它没有很好的说服力,因为它只是声明它有助于“开发人员生产力”,同时承认开发人员可以推出自己的产品。

Can any of the smart folks here come up with a better reason?

这里有聪明的人能想出更好的理由吗?

SUMMARY FROM ANSWERS GIVEN BELOW:

下面给出的答案摘要:



I think the most convincing reason is that using a standardized workflow platform such as WF (versus rolling your own) will allow you to leverage current and future tooling such as the Visual Designer, provided by MS and third parties.

我认为最有说服力的原因是使用标准化的工作流平台,如 WF(而不是滚动你自己的)将允许您利用当前和未来的工具,如 MS 和第三方提供的可视化设计器。

Also because it is part of the MS stack of .NET based technologies, it will likely have better integration/migration path with future MS technologies (such as Azure).

此外,由于它是基于 .NET 技术的 MS 堆栈的一部分,因此它可能会与未来的 MS 技术(例如 Azure)有更好的集成/迁移路径。

Finally, the number of developers with WF experience will increase (as it will benefit them career-wise), turning it into a basic commodity skill such as SQL or HTML, meaning it will become easier to find people who can start working with it with minimal ramp up time.

最后,拥有 WF 经验的开发人员数量将会增加(因为这将使他们在职业上受益),将其转变为基本的商品技能,例如 SQL 或 HTML,这意味着将更容易找到可以开始使用它的人最小的加速时间。

回答by Jeff Yates

There is some reasonably nice designer support in Visual Studio that I'd rather not have to roll for myself, and it's a framework supported by someone else rather than me, meaning someone fixes the architecture bugs and does the main testing, leaving me to test just my workflow. I mean, I could roll my own versions of GDI+ calls, but I'd rather not. Same goes for my own serialization framework, XML parser, or some other element of the .NET framework.

Visual Studio 中有一些相当不错的设计器支持,我宁愿不必为自己滚动,而且它是由其他人而不是我支持的框架,这意味着有人修复架构错误并进行主要测试,让我来测试只是我的工作流程。我的意思是,我可以推出自己版本的 GDI+ 调用,但我宁愿不这样做。我自己的序列化框架、XML 解析器或 .NET 框架的其他一些元素也是如此。

When it comes down to it, these things are provided as a toolkit. Whether you choose to use a tool or not depends entirely on the problem you're solving, the suitability of the tool, and the time and resources you have available to achieve the goal.

归根结底,这些东西是作为工具包提供的。您是否选择使用工具完全取决于您要解决的问题、工具的适用性以及您可用于实现目标的时间和资源。

回答by Oliver N.

I have had to create Workflow activities at my job, and I can't even tell you the answer.

我不得不在我的工作中创建工作流活动,我什至不能告诉你答案。

One not very valid reason is that invalid values/inputs can be determined and refused at design time for workflow diagrams, and so compile-time errors basically don't exist (assuming all that boilerplate code you wrote has no compile-time errors).

一个不太合理的理由是,可以在工作流图的设计时确定和拒绝无效值/输入,因此编译时错误基本上不存在(假设您编写的所有样板代码都没有编译时错误)。

回答by Guy Starbuck

The main reasons I can think of to lean towards using WF over another workflow framework are:

我能想到的倾向于使用 WF 而不是另一个工作流框架的主要原因是:

  1. Microsoft is supporting it as a core part of the framework, so it can/will be easier to integrate into their other technologies like Sharepoint and Azure "cloud applications"
  2. The tooling is likely to improve and be really slick in another few versions, which should improve developer productivity
  1. 微软支持它作为框架的核心部分,所以它可以/将更容易集成到他们的其他技术中,比如 Sharepoint 和 Azure“云应用程序”
  2. 该工具可能会在其他几个版本中得到改进并且非常灵活,这应该会提高开发人员的生产力

回答by jcollum

Short answer: it's freeand it gets the job done. If you can roll a better framework for managing workflow and want to spend your time on it, by all means do. But consider that your time is worth money, so how much money are you willing to commit to building a better framework for managing workflow? I could see that getting expensive.

简短的回答:它是免费的,它可以完成工作。如果你可以推出一个更好的框架来管理工作流,并想花时间在上面,一定要这样做。但是考虑到您的时间是值得的,那么您愿意投入多少钱来构建更好的工作流管理框架?我可以看到它变得昂贵。

Also, I'm pretty sure that persistence (to disk or SQL) is handled out of the box.

另外,我很确定持久性(到磁盘或 SQL)是开箱即用的。

回答by Mike Perrenoud

The choice to use WF takes some evaluation and I'm going to try and provide a fairly comprehensive list here on what the pros and cons are. Keep in mind that if you're going to use WF don't use anything other than WF4+ because it was rewritten and is significantly vetted past its predecessors.

选择使用 WF 需要一些评估,我将尝试在此处提供一个相当全面的列表,说明其优缺点。请记住,如果您打算使用 WF,请不要使用 WF4+ 以外的任何其他东西,因为它已被重写,并且经过了其前辈的大量审查。

Pros

优点

  • Cost
  • Flexibility
  • Durability
  • Distributability
  • Future
  • 成本
  • 灵活性
  • 耐用性
  • 可分配性
  • 未来

Cost

成本

The cost of WF is important to note when comparing it against other paths. Those paths may include BizTalk, an open source code based framework like Objectflow, or even rolling your own. Bear in mind that unless you need something significantly simplistic, rolling your own would be the most expensive approach every time. So, if you need a sizable piece of functionality but also need control over the source code I would recommend an open source framework.

在将 WF 与其他路径进行比较时,需要注意 WF 的成本。这些路径可能包括BizTalk,一个基于开源代码的框架,如Objectflow,甚至滚动你自己的。请记住,除非您需要非常简单的东西,否则每次都使用自己的方法是最昂贵的方法。因此,如果您需要相当大的功能,但还需要控制源代码,我会推荐一个开源框架。

Flexibility

灵活性

WF is a very flexible framework in contrast with a framework like BizTalk. In WF you can write your own custom activities and do what you need to do outside of the framework - this really gives you the power you need.

与 BizTalk 等框架相比,WF 是一个非常灵活的框架。在 WF 中,您可以编写自己的自定义活动并在框架外执行您需要执行的操作 - 这确实为您提供了所需的功能。

Durability

耐用性

WF includes a very powerful durability framework. It's durable in the sense that the state of a workflow can be persisted, the workflow can be set idle (to preserve resources), and then recalled later. But, that durability goes a lot further because it's already setup for durability across a host farm. In other words a workflow can be started on one host, persisted, and then recalled on another host.

WF 包括一个非常强大的持久性框架。从某种意义上说,它是持久的,工作流的状态可以持久化,工作流可以设置为空闲(以保留资源),然后再调用。但是,这种耐久性更进一步,因为它已经设置为跨主机场的耐久性。换句话说,工作流可以在一台主机上启动、持久化,然后在另一台主机上重新调用。

Assumes that the workflows are hosted via a web service (i.e. WorkflowService).

假设工作流是通过 Web 服务(即 WorkflowService)托管的。

Distributability

可分配性

WF is already setup to be distributed across a host farm.

WF 已设置为跨主机场分布。

Assumes that the workflows are hosted via a web service (i.e. WorkflowService).

假设工作流是通过 Web 服务(即 WorkflowService)托管的。

Future

未来

WF is the replacement orchestration engine for BizTalk and is in fact developed by the same people that built BizTalk. Therefore WF has a bright future in the Microsoft stack. In fact, right now Microsoft is working on building individual components to replace every feature of BizTalk with components. For example, Windows Server AppFabric(and more specifically the plug-in to IIS) is the replacement for the monitoring services that exist within BizTalk today.

WF 是 BizTalk 的替代编排引擎,实际上是由构建 BizTalk 的同一个人开发的。因此,WF 在 Microsoft 堆栈中有着光明的未来。事实上,现在微软正致力于构建单独的组件,用组件替换 BizTalk 的每个功能。例如,Windows Server AppFabric(更具体地说是 IIS 插件)是当今 BizTalk 中存在的监视服务的替代品。

Why is Microsoft doing this? Because BizTalk isn't really well suited for the cloud because it's one massive install, whereas the components they are building could be deployed to a cloud solution.

微软为什么要这样做?因为 BizTalk 不太适合云,因为它是一个大规模安装,而他们正在构建的组件可以部署到云解决方案。

Cons

缺点

  • Flexibility
  • Monitoring
  • 灵活性
  • 监控

Flexibility

灵活性

WF's flexibility can also be its pitfall because sometimes you don't need the flexibility that it provides and thus spend more time building stuff that you would otherwise want to just be included. Sometimes you need a framework that makes a lot of assumptions and maybe works off of convention instead (e.g. MVC). However, generally speaking I have found that this isn't true when coupling the WF4 framework with the open source extensionsprovided by Ron Jacobs.

WF 的灵活性也可能是它的缺陷,因为有时您不需要它提供的灵活性,因此需要花费更多时间来构建原本只想包含在内的东西。有时您需要一个框架来做出很多假设,并且可能会违反约定(例如 MVC)。但是,一般来说,我发现将 WF4 框架与Ron Jacobs 提供的开源扩展相结合时,情况并非如此。

Monitoring

监控

The monitoring for WF is still very young and this is its biggest pitfall. However, this will advance veryquickly over time and in the meantime you can build your own monitoring tools with custom trackingmechanisms.

WF 的监控还很年轻,这是它最大的陷阱。但是,随着时间的推移,这将非常迅速地推进,同时您可以使用自定义跟踪机制构建自己的监控工具。

Resources

资源

Your best resource is Ron Jacobs. I have never met somebody that is so willing to help the community of developers that have to use Microsoft's frameworks than him. Believe me, he's provided a vast amount of information surrounding WF via numerous channels, just get on Google and check it out.

您最好的资源是Ron Jacobs。我从未见过比他更愿意帮助必须使用 Microsoft 框架的开发人员社区的人。相信我,他通过众多渠道提供了大量有关 WF 的信息,只需上 Google 并查看即可。

回答by Prakash

Its a new technology Or you can say its latest with a promise of constantly updating features.

它是一项新技术 或者您可以说它是最新的,并承诺不断更新功能。

It respects the previous working environment and uses it and add those features which are very helpful with regards to the development of the long running programs(large projects).

它尊重以前的工作环境并使用它并添加那些对开发长期运行的程序(大型项目)非常有帮助的功能。

It produces all that features directly into the hands of the developer which were previously running at the back lacking the interaction between the inner core concepts and the programmer.

它将所有功能直接提供给开发人员,而这些功能以前在后台运行,缺乏内核概念和程序员之间的交互。

Yeah its a little complex but also it provides more power in the hands of the programmer.

是的,它有点复杂,但它也为程序员提供了更多的权力。

You can expect better frameworks and features in the coming future. Its the future of the programming so better we start learning it today.

在未来,您可以期待更好的框架和功能。它是编程的未来,所以我们今天开始学习它会更好。