Execute single workflow instance in parallel

2019-07-21 11:31发布

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 } }));

1条回答
相关推荐>>
2楼-- · 2019-07-21 12:08

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.

查看更多
登录 后发表回答