我应该在WF中使用状态机还是序列工作流程?

时间:2020-03-05 18:56:03  来源:igfitidea点击:

作为配置管理职责的一部分,我每周执行一次可重复的业务流程。该过程不会改变:我将更改细节下载到Excel中,打开电子表格并基于宏复制细节,从议程模板创建Word文档,使用Excel数据更新议程,从Word文档创建PDF,以及给他们发电子邮件。

这个过程很容易在序列工作流中表示,到目前为止,我就是用COM自动化来自动处理Excel和Word片段的。最重要的是,在"创建议程"和"发送议程"之间需要人为的步骤,其中,我查看变更细节并提出有关这些问题的问题,这些问题已添加到议程中。我目前有一个Suspend活动,可以在我手动执行此过程时暂停工作流程。

我的问题是,我应该重写工作流程以使其成为遵循业务流程中人类交互最佳实践的状态机,还是"挂起"活动是合理的解决方案?

解决方案

回答

不,我认为我们不必为此工作流使用状态机。但是,我建议更改"挂起"活动,因为:

The SuspendActivity activity
  temporarily stops the execution of the
  current workflow. Typically, you use
  the SuspendActivity activity to
  reflect an error condition that
  requires attention by an
  administrator. 
  
  When a workflow
  instance is suspended, an error is
  logged. You can specify a message
  string to accompany the error to help
  the administrator diagnose the problem
  with the SuspendActivity Error
  property. A suspended workflow
  instance can still receive messages
  that are queued up until the workflow
  is restarted. All the state
  information for the workflow instance
  is saved and is reinstated when the
  instance is resumed (using Resume).
  
  Source: MSDN

在工作流(序列机或者状态机)中添加人工任务的典型方法是定义外部数据交换接口并使用HandleExternalEvent活动(可能还可以是CallExternalMethod活动)。有关更多详细信息,请参阅以下文章:

  • 使用Windows Workflow Foundation构建状态机
  • 使用Windows Workflow Foundation进行简单的人工工作流程

回答

更新:Panos很好地说明了挂起活动。我同意它在工作流自动机中具有不同的目的。

如果我们感到担心的是工作流在各种状态之间的转换,那么状态机工作流就是理想的选择。否则,顺序就好了。

我们应该尝试解决的主要问题是,在等待人工交互(线程敏捷性)时,工作流不应占用线程。如果工作流在此期间处于空闲状态并持续存在(例如使用SqlWorkflowPersistenceService),则应该没有问题。