State History
Last changed: -


Is a member of the StateMachineWorkflowInstance object.

A simple example to print the state history every time a workflow goes idle:

static void Main(string[] args)
    using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
        SqlTrackingService tracking = new SqlTrackingService(@"Data Source=.\sqlexpress;Initial Catalog=WorkflowTracking;Integrated Security=True");
        tracking.IsTransactional = false;

        workflowRuntime.WorkflowIdled += new EventHandler<WorkflowEventArgs>(workflowRuntime_WorkflowIdled);

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


static void workflowRuntime_WorkflowIdled(object sender, WorkflowEventArgs e)
    WorkflowRuntime runtime = sender as WorkflowRuntime;
    StateMachineWorkflowInstance instance = new StateMachineWorkflowInstance(runtime, e.WorkflowInstance.InstanceId);

    Console.WriteLine("State history:");
    foreach (var item in instance.StateHistory)
        Console.WriteLine("\t{0}", item);

When you use this you might receive a InvalidOperationException with message: 'StateHistory' property requires the 'System.Workflow.Runtime.Tracking.SqlTrackingService' service. This is because it uses the SqlTrackingService to retreive all previous states from.