Sequential Workflow in Windows Workflow Foundation


Introduction: The sequential workflow style executes a set of contained activities in order one by one. We can add other composite activities to a sequential workflow to achieve parallelism, event-driven parallelism, data-driven execution, event-driven branching and familiar imperative control flow patterns such as conditional branching and iteration. We can also utilize the extensibility of Windows Workflow Foundation to write custom composite activities that implement whatever specific control flow patterns our solutions require.

Let see how to create Sequential Workflow:

Step 1 : Open Visual studio 2010.

  • Go to File->New->Project option.
  • Select Visual C#->Workflow->.NET Framework 3.5.
  • Select Sequential Workflow Console Application.
  • Click OK.
sequential1.gif

After creating the Application, designer window look like this:

sequential2.gif

Step 2: Add activity from Toolbox for Workflow.
  • Add a Code activity , IfElse activity, Delay activity.

activityseq.gif


Step 3: Go to Workflow1.cs class add these variables.

Variables:

private int i;
private
DateTime start, finish;

Step 4: Go to Design View and double-click in codeActivity1 and write the below code.

Code:

private
void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
   i = (new Random()).Next(10);
   Console.WriteLine("Number = " + i);
   Console.WriteLine("Started...");
   start = DateTime.Now;
}

Step 5: Go to Design View and click  ifElseActivity1.
  • Go to Properties->Condition row.
  • Select Declarative Rule Condition.
  • Set Condition Name LessThan.
  • Click Expression->Rule Condition Editor window write the below code.

seqential3.gif

Code:

this.i < 8

Step 6:  Same process for the other activity and write the below code for Greaterthan.

sequentiak4.gif

Code:

this.i > 9

Step 7: Go to Design View and double-click in codeActivity2 and write the below code.

Code:

private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{
   Console.WriteLine("Finished...");
   finish = DateTime.Now;
   Console.WriteLine("Time Elapsed : " + finish.Subtract(start));            
   Console.WriteLine("my sequential activity");
   Console.ReadLine();
}

Step 8: Now press F5 run it. We will get different outputs.

resultsequ1.gif

Step 9: Two possible outputs value are shown below.

resultsequ2.gif

Up Next
    Ebook Download
    View all
    Learn
    View all