如何用c#编写状态机?
我需要用 C# 编写快速运行的状态机。 我喜欢 Windows Workflow Foundation 库,但它太慢并且功能过于拥挤(即繁重)。我需要更快的东西,最好是使用图形实用程序来设计图表,然后吐出 C# 代码。 有什么建议吗? 谢谢!
I need to write state machines that run fast in c#.
I like the Windows Workflow Foundation library, but it's too slow and over crowded with features (i.e. heavy). I need something faster, ideally with a graphical utility to design the diagrams, and then spit out c# code.
Any suggestions?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最终,您可能需要重新设计的 .NET 4.0 中的 WF 引擎,因为它速度更快,并提供流程图活动(不完全是状态机,但适用于大多数场景)和良好的设计器 UI 体验。但由于它尚未发布,目前这可能不是一个好的答案。
作为替代方案,您可以尝试 stateless,这是一个专门用于在 .NET 中创建状态机程序的库。它似乎没有提供用户界面,但看起来非常适合实现您的其他目标。
Ultimately, you probably want the newly redesigned WF engine in .NET 4.0, as it is much faster and provides a flowchart activity (not quite a state machine, but works for most scenarios) and a nice designer UI experience. But since it's not yet released, that is probably not a good answer for now.
As an alternative, you could try stateless, a library specifically for creating state machine programs in .NET. It doesn't appear to provide a UI, but looks well-suited to fulfill your other goals.
是的,微软在状态机 WF 方面可能走在了时代的前面。顺序工作流程的接受度要好得多。
当我们决定使用状态机时,我们推出了自己的状态机。因为我们找不到带有 UI 的可接受的框架。这是我们的步骤。希望他们能帮助你。
创建您的状态接口:
创建状态并让它们实现接口:
在 main 中实例化状态
类。
当用户执行需要更改状态的操作时,调用方法来设置状态:
当然,操作将存在于 IApplicationState 的特定实例中。
Yeah, Microsoft may have been ahead of their time with State Machine WF. Sequential Workflows are being received much better.
When we decided on using a state machine, we rolled our own. because we couldn't find an acceptable framework with a UI. Here are our steps. Hope they'll help you.
Create your state interface:
Create the states and have them implement the interface:
Instantiate the states in your main
class.
When the user does something requiring a change of state, call the methods to set the state:
Of course, the actions will live in the particular instance of the IApplicationState.