Cannot create more than one WorkflowRuntime per AppDomain

I want to use workflow in 2 asp.net pages. This is how i am doing.
In first page i it will update one status and in second page it will update 2 nd status.

I am using the follwoing architecture

ASP.net page -- > Business Layer-- Windows Workflow - Dataaccess Layer

ASP.net PAge:
-

In this page first it has to run workflow then update database.

protected void btnSave_Click(Object sender, EventArgs e)
{
_businesslayer = new BusinessLayer.NewAccWorkFlow();
_businesslayer.Update("Analyst","Review");

}


Business LAyer:
-
namespace BusinessLayer
{
public class NewAccWorkFlow
{


WorkflowRuntime wf;

private void Update Status(string inputType, string status)
{
Dictionary<string, object> parms = new Dictionary<string, object>();
parms.Add("Type", inputType);
parms.Add("Status", status);
wf = new WorkflowRuntime();

WorkflowInstance wfInstance = wf.StartWorkflow(type, parms);
id = wfInstance.InstanceId;
}
}
}


Probem here is:

First time when you save page its executing well. When you save first time its creating instance of workflow and executing well. But the user can save different data again on the same page. When you do that its trying to create another instance
which is already in app domain. In both pages i am going to call Update methos in Business Layer.

Is this the better way to do?
Could you suggest the way that i can use my work flow in multiple pages (where exactly i have to instantiate and use in multiple pages.)

I really appriciate for your help

Thanks

Sridhar

[1760 byte] By [sridharhyderabad] at [2007-12-25]
# 1

Hello Sridhar,

You can not really change the data inside your workflow once its started from your host. What you could do is whenever the user wants to change some piece of data or property in your workflow, send an event (containing the new data values, use the "HandleExternalEventActivity") to your workfow and handle this event by changing the approriate data values. This is the typical supported way of communicating information from the host to your workflow. Another thing you could do is create a workflow service that sets/gets the neccessary data to your workflows, and use this service to set/get the data from your host and from your workflows. This way you are taking the data out from your workflows and hence they can be access directly by your host.

And just a minor comment about the title, you do can now create more than one WorkflowRutnime in one AppDomain, although I dont think thats what you want in the scenario you just described.

KhalidAggag at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified