Search code examples
c#.networkflow-foundation-4

How to change a WWF (Windows Workflow Foundation) flow chart at runtime


I am trying to use Windows Workflow Foundation (Flow charts) in my application. I am new to this. I read that we can change the flow chart ( conditions and all) in run time. From the tutorials I saw I couldn't understand how I can do that. I mean this is not like a rule engine where we have a xml file in the data base. We are taking separate project for designing flow charts and sequences. Won't I require to build that project and deploy it to make my changes reflect in the consumer application?


Solution

  • If you store your workflow XAML in the database or a file, you can load it at runtime without rebuilding the project and deploying.

    Here is an example of dynamically executing a workflow loaded at runtime from an XML file:

    var activity = ActivityXamlServices.Load("SavedWorkflow.xml");
    
    WorkflowInvoker.Invoke(activity);
    

    As you see from the example the Load method above returns an Activity object that you can modify (e.g. change the conditions) prior to executing the workflow.