Workflow Foundation 中嵌套活动的性能注意事项

Performance considerations with nested activities in Workflow Foundation

我正在审阅一个相当大的 Windows Workflow Foundation .xaml 文件。

我发现了几个嵌套的 Sequence 活动。

示例:

注意:这是一个简单的例子来帮助说明我的问题。

Main Sequence

查询数据序列将包含与设置变量和查询数据源相关的活动。

写入 CSV Sequence 包含与设置变量和写入 CSV 文件相关的活动。

除了逻辑组织活动外,这两个子活动没有其他用途。

我正在审阅的 .xaml 文件非常大且复杂。

构建具有多个嵌套活动的工作流是否存在负面性能影响?

嵌套活动存在负面性能问题。这样做的原因是工作流实例在两个活动的单个线程上 运行。 WF 运行 时间安排使用类似队列的结构在该线程上工作。当 activity 执行时,它只是用 运行 时间安排其子活动。因为活动进行阻塞、同步工作,所以它们阻塞工作流正在运行的线程。运行。

Workflow state machine transitions in and out of deeply nested states are more expensive due to activity tree navigation and AEC cloning. You should try to avoid having deeply nested states as much as possible.

activity 实例状态由工作流 运行 时间通过 Activity 执行上下文 (AEC) 自动管理。工作流 运行time 使用 AEC 维护 activity 实例状态并在需要时 运行 补偿逻辑。

When an activity needs to be re-executed, a new AEC is created using the BinaryFormatter class. This operation can have a performance impact on your workflow application, especially in cases where the AEC being cloned is complex (for example, when there are multiple nested activities).

解决方案是运行工作流异步使用WorkflowApplication对象。