Execute single workflow instance in parallel

北慕城南 提交于 2019-12-12 17:24:27

问题


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:


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.



来源:https://stackoverflow.com/questions/8856224/execute-single-workflow-instance-in-parallel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!