Running Workflow Synchronously

on Monday, August 24, 2009

ManualWorkflowSchedulerService service = new ManualWorkflowSchedulerService();

using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
workflowRuntime.AddService(service);
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
Console.WriteLine(e.OutputParameters["Result"].ToString());
waitHandle.Set();
};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{

Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication1.Workflow1), data);
instance.Start();
service = workflowRuntime.GetService();
if (service != null)
service.RunWorkflow(instance.InstanceId);
}

0 comments: