public class WorkflowIsolatedHost{ private WorkflowRuntime workflowRuntime; public WorkflowIsolatedHost() { Console.WriteLine("Created workflow instance in AppDomain: " + AppDomain.CurrentDomain.FriendlyName); // Fire up the engine. workflowRuntime = new WorkflowRuntime(); workflowRuntime.StartRuntime(); // Load our schedule type. Type type = typeof(MultipleAppDomainWorkflowTest.Workflow1); workflowRuntime.WorkflowCompleted += OnWorkflowCompletion; workflowRuntime.StartWorkflow(type); } void OnWorkflowCompletion(object sender, WorkflowCompletedEventArgs instance) { Console.WriteLine("Workflow instance finished in AppDomain: " + AppDomain.CurrentDomain.FriendlyName); workflowRuntime.StopRuntime(); }}
public static class WorkflowCreator{ public static void CreateIsolatedWorkflowInstances(int numInstances, string assemblyName, string workflowHostName) { for (int i = 0; i < numInstances; i++) { AppDomain curDomain = AppDomain.CreateDomain("WorkflowInstance" + i.ToString()); curDomain.CreateInstance(assemblyName, workflowHostName); } }}
class Program{ static void Main(string[] args) { WorkflowCreator.CreateIsolatedWorkflowInstances(5, System.Reflection.Assembly.GetExecutingAssembly().FullName, typeof(WorkflowIsolatedHost).ToString()); }}