Dec 9, 2008

ManualWorkflowSchedulerService

By default, workflow runtime use DefaultWorkflowSchedulerService as scheduler, what this means is that the workflow instance run in a separate thread. So if you want to wait for the workflow to finished, you need AutoResetEvent object to synchronize the thread. But in asp.net you make want to use a single thread. Here is an article Using Workflows with ASP.NET.

//you need to add this to to runtime initialization
ManualWorkflowSchedulerService manualService = new ManualWorkflowSchedulerService();
_workflowRuntime.AddService(manualService);


//you need to perform additional steps
//to run the workflow.
WorkflowInstance instance
    = _workflowRuntime.CreateWorkflow(
        typeof(SimpleCalculatorWorkflow.Workflow1),
            wfArguments);
instance.Start();

ManualWorkflowSchedulerService manualScheduler = 
    _workflowRuntime.GetService(typeof(ManualWorkflowSchedulerService))
    as ManualWorkflowSchedulerService;
manualScheduler.RunWorkflow(instance.InstanceId);