Microsoft .NET Framework 3.5 Documentation
This sample demonstrates a basic Windows Workflow Foundation (WF) application, showcasing how to define, host, and execute a simple workflow.
BasicWorkflow.xaml
)The workflow is defined in a XAML file. This example uses a simple SequentialWorkflow
with an WriteLine
activity.
<Activity mc:Ignorable="sap"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
x:Class="BasicWorkflow"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="Message" Type="x:String" />
</x:Members>
<WriteLine Text="{x:Bind Message}" />
</Activity>
Program.cs
)The C# host application loads the workflow from the XAML file and executes it.
using System;
using System.Activities;
using System.IO;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Loading workflow...");
// Load the workflow definition from XAML
string workflowXaml = File.ReadAllText("BasicWorkflow.xaml");
Activity workflow = ActivityXamlServices.Load(new StringReader(workflowXaml));
// Define workflow input parameters
var inputs = new Dictionary<string, object>
{
{ "Message", "Hello from the Workflow Application Sample!" }
};
Console.WriteLine("Executing workflow...");
// Create a workflow host and run the workflow
var host = new WorkflowInvoker(workflow);
var outputs = host.Invoke(inputs);
Console.WriteLine("Workflow executed successfully.");
// Access any workflow outputs (if any)
// foreach (var output in outputs)
// {
// Console.WriteLine($"Output: {output.Key} = {output.Value}");
// }
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
BasicWorkflow.xaml
and paste the XAML code above.Program.cs
file with the C# host application code.System.Activities.dll
.Download the complete source code for this sample: