Introduction: The Custom activities are the units of work that are composed to produce workflow based functionality. In WF4, activities explicitly declare their inputs and outputs via arguments.

Step 1: Open Visual Studio and select the File option.

IMAGE1.gif

Let see how to create Sequential Workflow :

Step 2: Open Visual Studio 2010.

After creating the Application, the designer window look like this:

workflow1.gif

Step 3 : Add an activity from Toolbox for Workflow.

Code :

namespace WorkflowLibrary1
{
public sealed partial class Workflow1 : SequentialWorkflowActivity
{
public Workflow1()
{
InitializeComponent();
}
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("start 3.5 workflow");
}
private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("finish 3.5 workflow");
}
}
}

Step 4 : Go to Workflow1.cs [Desaign] drag another codeActivity and write the below code.

Code :

namespace WorkflowLibrary1
{
public partial class customActivity1 : SequenceActivity
{
public customActivity1()
{
InitializeComponent();
}
public static DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeo
(string), typeof(customActivity1));
[DescriptionAttribute("Message")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute
(DesignerSerializationVisibility.Visible)]
public string Message
{

get
{
return ((string)(base.GetValue(MessageProperty)));
}
set
{
base.SetValue(MessageProperty, value);
}
}
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine(this.Message);
}
}
}

Step 5 : Go to Solution Explorer and right-click.

Step 6 : Go to workflow1.xaml file.

interop12.gif

Creating a Custom Activity:

Step 7: Go to Solution Explorer and right-click.

interop1.gif

Throwing an Exception:

Step 8: Open Custom.cs [Design] option.

Invoke Custome Activity:

Step 9 : Drag a WriteLine activity onto the Catch section.

trycatch1.gif

Step 10 : Press F5 to run the application.

cu1.gif