index > Windows Workflow Foundation > Cannot create more than one WorkflowRuntime per AppDomain????

Cannot create more than one WorkflowRuntime per AppDomain????

I have a webform with a button. On the button click i am calling the workflow and getting the response for the first time. The next time i click i am getting the exception "Cannot create more than one WorkflowRuntime per AppDomain"

public partial class _Default : System.Web.UI.Page

{

WorkflowRuntime wr;

private string _returnValue=string.Empty;

private string _returnMessage=string.Empty;

public string ReturnValue

{

get

{

return _returnValue;

}

set

{

_returnValue = value;

}

}

public string ReturnMessage

{

get

{

return _returnMessage;

}

set

{

_returnMessage = value;

}

}

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Page_Unload(object sender, EventArgs e)

{

if (wr != null)

{

if (wr.IsStarted)

{

wr.StopRuntime();

}

wr = null;

}

}

protected void ClickButton_Click(object sender, EventArgs e)

{

if (wr == null)

{

wr = new WorkflowRuntime();

wr.StartRuntime();

}

AutoResetEvent waitHandle = new AutoResetEvent(false);

Dictionary<string, object> parameters = new Dictionary<string, object>();

parameters.Add("UserName", "User1");

wr.WorkflowCompleted += delegate(object sender1, WorkflowCompletedEventArgs ex1)

{

ReturnValue=ex1.OutputParameters["Message"].ToString();

waitHandle.Set();

};

wr.WorkflowTerminated += delegate(object sender2, WorkflowTerminatedEventArgs ex2)

{

ReturnMessage=ex2.Exception.Message;

waitHandle.Set();

};

WorkflowInstance instance = wr.CreateWorkflow(typeof(Samples.DisplayMessageWorkflow), parameters);

instance.Start();

waitHandle.WaitOne();

Response.Write("Return value is " + ReturnValue);

}

}

shangan
That's correct. You're currently basically trying to create a workflow runtime per request.

What you want to do is create your workflow runtime as an application global instance (this is usually done in ASP.NET from your Global.asax) and then use it to create and run workflow instances.

Check out Dino Spositos' article on MSDN Mag, which talks about some of the issues of hosting the workflow runtime in ASP.NET



Tomas Restrepo [MVP]
Tomas Restrepo
Unfortunately some on Dino's article is out of date. In particular the information on the WorkflowWebRequestContext class, which no longer exists. Try the samples found here.


MS Workflow SDE/T - This posting is provided "AS IS" with no warranties, and confers no rights.
Tom Lake
Thanks for the correction Tom, yes, that's right. I was mostly refering to the design comments on the article about keeping a single runtime :)



Tomas Restrepo [MVP]
Tomas Restrepo

This limitation was removed post beta 2. Try upgrading to the most recent CTP.

Thanks,
Joel West
MSFTE - SDE in WF runtime and hosting

This posting is provided "AS IS" with no warranties, and confers no rights

Joel West
reply 5

You can use google to search for other answers

 

More Articles

• Check For Existing WorkflowRuntime In Current AppDomain And More
• A workflow application from Visual Studio hosted in Sharepoint 20...
• duplicate ruleconditionsattribute
• How do I implement a custom activity like the Policy activity.
• Check-Off WorkItem/Event List
• How to connect to workflow in a single application ?
• Index was outside the bounds of the array in Windows Work Flow
• Why does ListenActivity always have two EventDrivenActivity
• FileWatchService and State Machine Workflows
• Using a Workflow by a Windows and a Web Application at the same t...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Synchronizing Activities
• Hosting the WorkflowDesignerControl in A
• Copy List Item activity in SharePoint de
• Tracing persistance erors
• State Machine Exception Handling
• Question about custom State Activity
• How to keep an activity still in Excutin
• WWF Beta 1.2 not installing properly
• SqlPersistanceService - Changing workflo
• SequenceActivity within a Replicator
• State Machine Workflow with multiple Com
• The new kid on the n-tier layer block?
• Retrieving data with workflow
• WorkflowWebRequestContext.Current always
• How do I implement a custom activity lik

Hot Articles

• WF Designer Host Example
• DependencyProperty error...
• How to implement an automated Purchase O
• SharePoint WF host?
• Hosting designer on asp page
• Making properties values persist in a wo
• Emulating the listen-->(EventDriven,E
• How do you bind a property for 2 custom
• Sharepoint Designer error using workflow
• How do i record what i do????
• Latest on ASP.Net & Workflow
• Dynamically load policyActivity ruleSet
• Problem with Workflows and WebServices
• WorkFlow Projects not showing in VS 2005
• Host WF in Client applcation

Recommend Articles

• Problems with Persistance and ASP.NET
• RuleSet Editor
• Custom serializing of activity properties
• web service - response/fault
• How to return the SqlDataReader from Wor
• designer and project template support fo
• I know WWF is still in Beta form but it
• Stack Overflow in the rule designer
• correlation
• using Dataset to exchange data
• Mixing ManualSchedulerService and Defaul
• make a simple ASP.Net workflow
• FileWatchService and State Machine Workf
• sync vs. async
• knowing wich activity idled the workflow.