SIGN UP MEMBER LOGIN:    
ARTICLE

Sequential Workflow in Windows Workflow Foundation

Posted by Davin Martyn Articles | Workflow Foundation in C# October 12, 2011
The sequential workflow style executes a set of contained activities in order one by one.
Reader Level:

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

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor