The Problem SolverWIndows Workflow Foundation
HomeShow ChangesEditPrintRecent ChangesSubscriptionsLost and FoundFind ReferencesRename



3-6-2008 18:56:223-6-2008 18:56:0024-10-2006 19:32:5321-10-2006 13:45:10

List all versions

Manual Workflow Scheduler Service
ManualWorkflowSchedulerService is used for synchronous execution of workflow instances.

ManualWorkflowSchedulerService is used for synchronous execution of workflow instances. If this service is being used, the workflow instances are executed on the calling thread from the host application, thus blocking the execution of the host application until the workflow instance becomes idle.

When using ManualWorkflowSchedulerService in an WebService environment with the DelayActivity you need to set the UseActiveTimers of the ManualWorkflowSchedulerService to true and make sure the ASP.NET process is reloaded when IIS unloads it.

If you want to use the ManualWorkflowSchedulerService without the UseActiveTimers you are responsible for restarting a workflow after the DelayActivity has expired. To do so you need some kind of periodic event like a timer. The following example uses a Timer but as that is what the UseActiveTimers option actually does it is just an example of the sort of code you need to write.

private static Timer _timer;

static void Main(string[] args)
    using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
        ManualWorkflowSchedulerService scheduler = new ManualWorkflowSchedulerService();

        _timer = new Timer(TimerCallback, workflowRuntime, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(250));

        WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleApplication1.Workflow1));



static void TimerCallback(object state)
    WorkflowRuntime workflowRuntime = state as WorkflowRuntime;

    if (workflowRuntime.IsStarted)
        ManualWorkflowSchedulerService scheduler = workflowRuntime.GetService<ManualWorkflowSchedulerService>();
        var workflows = workflowRuntime.GetLoadedWorkflows();
        foreach (var item in workflows)
            if (item.GetWorkflowNextTimerExpiration() < DateTime.UtcNow)

The important part if to use the WorkflowInstance GetWorkflowNextTimerExpiration function that returns the DateTime (in UTC) that the next timer expires. If thers is no pending DelayActivity it returns December 31th 9999 23:59:59.

See also: DefaultWorkflowSchedulerService

Wiki Usage

This wiki site is supposed to be a shared resource. As a shared resource everyone is encouraged to add new content or modify existing content!

Enjoy the WF wiki.

Recent Topics