并行执行单个工作流程实例 [英] Execute single workflow instance in parallel

查看:120
本文介绍了并行执行单个工作流程实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个工作流程,并且想并行执行多次:

Let's say I have a workflow, and I want to execute it many times in parallel:

System.Threading.Tasks.Parallel.For(
    0, 
    100, 
    i => WorkflowInvoker.Invoke(
        new Workflow1(),  
        new Dictionary<string, object> { { "Num", i } }));

我想知道以这种方式执行它是否合法:

I wonder, is it legal to execute it this way:

var w = new Workflow1();
System.Threading.Tasks.Parallel.For(
    0, 
    100, 
    i => WorkflowInvoker.Invoke(
        w, 
        new Dictionary<string, object> { { "Num", i } }));

推荐答案

是的,以这种方式执行工作流程定义是合法的".就调用而言,工作流定义本身是线程安全的.实际上,它是强烈建议您始终缓存工作流程定义以在应用程序中重复使用.这是因为定义只是执行的模板,每次执行本身都会导致一个全新的状态.

Yes it is "legal" to execute a workflow definition that way. The workflow definition itself is thread safe as far as invocation goes. In fact, it is highly recommended you always cache the workflow definition for reuse in your apps. This is because the definition is just a template for the execution, the execution itself results in an entirely new state each time.

这篇关于并行执行单个工作流程实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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