locked
Spawning multiple instances of the same workflow RRS feed

  • Question

  • I am currently using WWF v2.0beta and completed building a workflow project that handles one instance of the workflow.  I am interested in making this project multithreaded and have it handle multiple instances.  What is the correct process to do this?

    What my program does is that it has a listener that waits for messages, when it gets a new message it should spawn off a new instance of the workflow.  For the single instance example the workflow is started in the Program.cs file with the following command:

    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(RecvMsg.Workflow1), parameters);

    instance.Start();

    I would like to spawn off the additional instances of the workflow from the main program instead of invoking a workflow from within a workflow.  What is the correct way to this?  Examples would be great. 

    Jason

    Friday, April 7, 2006 6:11 PM

Answers

  • Hi Jason,

    Everytime you call CreateWorkflow(), you've created a new instance.  If your program waits for messages from somewhere, then in your listener event handler you can simply make calls to CreateWorkflow() as many times as necessary.

    You can keep track of your instances via the InstanceId property on WorkflowInstance (which you'll probably store in some dictionary).  Everytime an instance completes/terminates/etc., the corresponding event will be raised on the WorkflowRuntime, all of which you can subcribe to.  When your event handler is called, you will be passed the specific instance.

    Thanks,
    Angel

    Friday, April 7, 2006 6:49 PM
    Moderator
  • No, what you're thinking of is one WorkflowRuntime per AppDomain.  Workflow instances are just threads kicked off by the workflow runtime.  You can kick off as many as you want.  :-)

    -Angel

    Friday, April 7, 2006 10:36 PM
    Moderator

All replies

  • Hi Jason,

    Everytime you call CreateWorkflow(), you've created a new instance.  If your program waits for messages from somewhere, then in your listener event handler you can simply make calls to CreateWorkflow() as many times as necessary.

    You can keep track of your instances via the InstanceId property on WorkflowInstance (which you'll probably store in some dictionary).  Everytime an instance completes/terminates/etc., the corresponding event will be raised on the WorkflowRuntime, all of which you can subcribe to.  When your event handler is called, you will be passed the specific instance.

    Thanks,
    Angel

    Friday, April 7, 2006 6:49 PM
    Moderator
  • But isn't it true that you can only run one workflow per appDomain so calling createWorkflow() when the same workflow is already running would not work?

    Jason

    Friday, April 7, 2006 9:00 PM
  • No, what you're thinking of is one WorkflowRuntime per AppDomain.  Workflow instances are just threads kicked off by the workflow runtime.  You can kick off as many as you want.  :-)

    -Angel

    Friday, April 7, 2006 10:36 PM
    Moderator