自动推进状态机无状态 [英] Auto advancing state machine with Stateless

查看:198
本文介绍了自动推进状态机无状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试无状态(HSM在C#)( https://code.google。 COM / p /无国籍/ )最近和我遇到,我真的不知道如何实现的东西。

I've been experimenting with Stateless (HSM in C#) (https://code.google.com/p/stateless/) lately and I've come across something that I'm not really sure how to achieve.

让我们说我有以下状态:

Let's say I have the following states:


  • 开始

  • Start.

连接

完成

我想要实现的是:在建立TCP连接(在连接状态)时,前进到读状态。或者,如果失败,前进到完成状态(它可能返回到连接状态,并尝试超时后一个新的连接)。

What I'm trying to achieve is: when the TCP connection (in the Connect state) is established, advance to the Read state. Or, if it fails, advance to the Finish state (where it may return to the Connect state and attempt a new connection after a timeout period).

我怎样才能实现使用无状态,因为从国家内部激活触发器这种自动推进功能会导致堆栈溢出异常?

How can I achieve this auto advancing feature using Stateless, since firing triggers from within the states can cause a stack overflow exception?

干杯

推荐答案

由于我发现关于无国籍没有本地的解决方案做我问,我结束了在任务

Given that I found no native solution on Stateless to do what I asked, I ended up wrapping the .Fire(trigger) in a task

Task.Start(() => _stateMachine.Fire(trigger));



这样做,意味着国家机器不进自己每说,但它是相当具有先进外部源,解决所述SO异常。

Doing so, means that the state machine does not advance itself per say, but it's rather advanced by an external source, solving the SO exception.

这篇关于自动推进状态机无状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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