Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Gauge for SharePoint
Search :       Advanced Search »
Home » WWF » Getting started with the Windows Workflow

Getting started with the Windows Workflow

This article show how to get started with Workflow Foundation API in .NET 3.5 and Visual Studio 2008.

Author Rank :
Page Views : 3205
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Introduction:

Windows Workflow Foundation is the programming model, engine and tools for quickly building workflow enabled applications on Windows. It consists of .NET classes, an in-process workflow engine, and designers for Visual Studio.

WF allows for two types of workflows. Sequential workflow is one that executes a series of steps in a defined sequence.

State machine workflow represents an ongoing project, in which a system continually transitions from one state to another. In this case, activities are not attached to a state.

Getting Started:

Workflow projects are created in the same way as other projects types in Visual Studio 2008. After starting Visual Studio 2008, you select File >>Project. In the Templates side, you select a Workflow type application.

In this example I am choosing Sequential Workflow Console Application template as you can see in Figure 1.

Figure 1.

This is the initial view of the visual workflow designer in Figure 2.

An activity represents a step in the workflow and is the fundamental building block of all WF workflows. All activity either directly or indirectly derive from the base class System.Workflow.ComponentModelActivity class.

Figure 2.

If you look at the Solutions Explorer, you will see something like this.

Figure 3.

Now, if you take a look at the Toolbox, you wull see a list of the standard activities available in Visual Studio 2008.

 

Figure 4.

Just drag and drop Code activity onto the workflow. The Code activity is a simple way to execute any code that you want as a step in the workflow.

 

Figure 5.

 

Figure6.

 

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

        {

            Console.WriteLine("Hello Raj Beniwal!! Welcome to WF!");           

        }

Figure 7.

When workflow has been implemented it adds new file Program.cs, which has following code.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.Workflow.Runtime;

using System.Workflow.Runtime.Hosting;

 

namespace GettingStartedWF

{

    class Program

    {

        static void Main(string[] args)

        {

            using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())

            {

                AutoResetEvent waitHandle = new AutoResetEvent(false);

                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};

                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)

                {

                    Console.WriteLine(e.Exception.Message);

                    waitHandle.Set();

                };              

 

 

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

                instance.Start();

 

                waitHandle.WaitOne();

 

            }

        }

    }

}

 

Now I am showing how to pass parameters in workflow. In WF parameters will be passed directly from the host console application.

private void codeActivity1_ExecuteCode(object sender, EventArgs e)

        {

            Console.WriteLine("Hello {0}, {1}", Name,  Message);

        }

 

        public string Name

        {

            get;

            set;

        }

       

        public string Message

        {

            get;

            set;

        }

 

 

static void Main(string[] args)

        {

            using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())

            {

                AutoResetEvent waitHandle = new AutoResetEvent(false);

                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};

                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)

                {

                    Console.WriteLine(e.Exception.Message);

                    waitHandle.Set();

                };

 

 

                Dictionary<string, object> wfArguments = new Dictionary<string, object>();

                wfArguments.Add("Name", "RAJ!");              

                wfArguments.Add("Message", "How you doing???");

 

 

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(GettingStartedWF.Workflow1), wfArguments);

                instance.Start();

 

                waitHandle.WaitOne();

 

                Console.WriteLine("Press any key to exit");

                Console.ReadKey();

            }

        }

For more information see attached application.

Figure 8.

Summary

In this example you saw how to get started with WF step by step.

 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Raj Kumar

Raj Kumar is a Microsoft MVP and Senior Software Engineer with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, Visual Basic .NET, SQL Server 2005/2008, Oracle, WPF, WCF, XAML and Silverlight. He has over 6 years of IT experience working most on Microsoft technologies. He holds Master's degree in Computer Science. When he is not writing code, he likes to write articles and play cricket.

Reach him at raj2511984@gmail.com 

 

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
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.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
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.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.