views:

212

answers:

4

If I have have a WorkflowInstance can I executed twice in a row?

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(...));
instance.start();
instance.start();

When I do this I get and exception telling me that I don't have a persistence service configured. However my question is: after I execute the WorkflowInstance once can a instance be run a second time, or dos it become unusable? Do I have to create another instance everytime I want to executed?

+1  A: 

As per the specifications of WorkflowInstance you can start the instance only once

have a look at http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.start.aspx

An InvalidOperationException is thrown if the instance is already running

Rutesh Makhijani
A: 

Yes I see I can't start an instance twice. However, what I wanted was to create the instance once and be able to run the workflow several times.

My problem is that WorkflowInstance creation is somewhat heavy.

Megacan
A: 

A workflow Instance, once started, moves forward through the workflow definition and then terminates. It cannot be "reused" to execute another workflow the way an object can be cached and reused.

There are several things you can do to improve the performance of your workflow, depending on how it is built.

Dave Swersky
A: 

As per Rutesh's answer, you cannot start the same instance twice. If the workflow has been unloaded (i.e. persisted) you can load the workflow again using WorkflowInstance.Load().

MattK