When should we use a sequential workflow and when should we use state machines?

 Posted by ArticlesMaint on 9/18/2009 | Category: WWF Interview questions | Views: 7972

If the workflow is very rigid then you go for sequential workflow and if the workflow is dynamic then go for State machine workflow. For instance you have placed an order and the order will not pass until your supervisor approves is a rigid flow. Because your order has to be approved by, a supervisor or else it will not be approved. But what if your order moves from one place to other place. For instance, it moves from approval to waiting and then clarification a state machine workflow model is more appropriate.
Below is a simple code snippet which shows practically how to use sequential workflow. Let try to understand step by step as marked in the figure:-
1 - First you need to select System. Workflow namespace.
2, 3, and 4 - In these three steps we created code object and linked them with activity.
5, 6, 7, and 8 - We start the workflow and create workflow instance object to run the sequential workflow. You can see the output in 8. Depending on how you add the activity in section 3, it executes sequentially. Because we have added codeactivity1, first it executes the first activity first. The sequence on how you add the activity to the activities collection the activities are run.

Figure: - 3 Code snippet for workflow

Note: - The above code snippet was developed with out using designer. The whole point was to make you understand what happens behind the scenes. In real projects you will be dependent on designer rather than coding manually. You can find the above code in SimpleWorkFlowSampleManual folder.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response