sodcalculator

10 Tech How-To

Windows Workflow Foundation: How to Choose a Workflow Framework

Guide 10-55840 · Updated · Step by step

To choose a workflow framework for Windows Workflow Foundation (WF), you must first decide whether you need the built-in WF runtime or a third-party library like Elsa Core, Workflow Core, or Stateless, based on your workflow’s complexity, hosting environment, and need for visual design. This article explains the key differences and provides a decision framework to help you pick the right tool for your project.

Background: What Is Windows Workflow Foundation?

Windows Workflow Foundation is a Microsoft framework for building workflow applications on the .NET platform. It was introduced with .NET Framework 3.0 in 2006 and has evolved through several versions. WF provides a runtime engine, a visual designer (in Visual Studio), and a set of activities (building blocks) that you can use to model long-running processes, such as document approval, order processing, or state machine transitions.

WF is not a standalone product; it is a library that you host inside your application. You define workflows either in XAML or in code, and the WF runtime executes them. The framework supports persistence, tracking, and compensation, making it suitable for enterprise scenarios where workflows may span hours or days.

How Windows Workflow Foundation Works

At its core, WF uses a model of activities arranged in a tree. Each activity represents a step (e.g., Delay, If, While) or a custom action. The runtime executes these activities according to the control flow you define. Two primary workflow types exist:

  • Sequential workflows – steps run in a fixed order, with branching and loops.
  • State machine workflows – the workflow moves between states based on events or conditions.

WF also supports long-running workflows that can be unloaded from memory while waiting for external input (like a user approval). The runtime persists the workflow state to a database and resumes it when the event arrives. This is handled by the WorkflowApplication or WorkflowServiceHost classes.

How to Choose a Workflow Framework

When deciding between WF and an alternative, consider the following factors:

  1. Hosting environment – Are you building a desktop app, a web app, or a microservice? WF is tightly coupled to .NET and Windows, though it works on .NET Core/5+ via the System.Workflow.Runtime package (though not all features are ported). Third-party libraries like Elsa Core are designed for modern ASP.NET Core and can run cross-platform.
  2. Visual design requirement – If you need a drag-and-drop designer for non-developers, WF’s Visual Studio designer is powerful but requires Visual Studio. Elsa Core offers an embedded, web-based designer that you can integrate into your app.
  3. Workflow complexity – For simple, linear processes, a lightweight library like Workflow Core might suffice. For complex state machines with many states and transitions, WF’s built-in state machine is mature, but you can also use Stateless (a small library) or Elsa.
  4. Persistence and tracking – WF has built-in persistence (SQL Server, etc.) and tracking. Elsa Core also supports persistence via EF Core. Workflow Core requires you to implement your own persistence if needed.
  5. Community and maintenance – WF is maintained by Microsoft but has seen limited feature additions in recent years. Elsa Core and Workflow Core are open-source with active communities. Check the project’s activity before adopting.
  6. Learning curve – WF has a steep learning curve due to its many concepts (activities, bookmarks, compensation). Simpler libraries may be easier for small teams.

Common Problems with WF and How to Avoid Them

Developers often encounter these issues when using WF:

  • Versioning – Updating a workflow definition while instances are running is tricky. WF’s default behavior is to use the same definition for all instances, but you can implement versioning by using different workflow types or by using the WorkflowIdentity class.
  • Debugging – Workflow execution is asynchronous and may be unloaded; debugging can be hard. Use WF’s tracking and tracing to log execution.
  • Performance – WF adds overhead for simple tasks. For high-throughput, short-lived operations, a simple code-based state machine may be faster.
  • Persistence configuration – Setting up the persistence store incorrectly can cause failures. Ensure you run the SQL scripts provided by Microsoft to create the required tables.

Comparison: WF vs. Elsa Core vs. Workflow Core vs. Stateless

Here’s a practical comparison to help you decide:

  • Windows Workflow Foundation – Best for enterprise apps already on .NET Framework or .NET Core, needing a visual designer and built-in persistence. It’s powerful but heavy.
  • Elsa Core – A modern, open-source workflow library for .NET Core/5+. It provides a web-based designer, supports C# expressions, and is easier to embed in ASP.NET Core apps. Good for SaaS applications where users define their own workflows.
  • Workflow Core – A lightweight, fluent-API library for .NET Standard. It supports sequential and parallel workflows, but no visual designer. Best for simple, code-defined workflows.
  • Stateless – A tiny library for state machines, not full workflows. Use it when you need a finite state machine without persistence or long-running features.

Costs and Licensing

Windows Workflow Foundation is included with .NET, so there is no additional licensing cost if you already use .NET. However, the Visual Studio designer is only available in Visual Studio editions that include the Workflow Designer (e.g., Professional and Enterprise). Third-party libraries like Elsa Core and Workflow Core are open-source (MIT license), so they are free to use, but you must consider the cost of learning and maintaining them. There are also commercial workflow products (e.g., Nintex, K2) that offer more features but at a higher price.

Safety and Best Practices

When implementing workflows, follow these safety guidelines:

  • Always persist critical workflow state before an external event, so you can resume after a crash.
  • Use compensation activities (e.g., CompensableActivity in WF) to undo side effects if a later step fails.
  • Set timeouts on delays and external calls to avoid workflows stuck forever.
  • Test with long-running scenarios to ensure your persistence store handles concurrency.
  • For web applications, host workflows in a separate process or service to avoid blocking the web server.

Frequently Asked Questions

Is Windows Workflow Foundation still supported in .NET Core?

Yes, but with limitations. The System.Workflow.Runtime package is available for .NET Core 3.1 and later, but not all features (like XAML designer) are fully supported. Microsoft has not actively developed WF since .NET Framework 4.8, so for new projects, consider a third-party library.

Can I use WF in a microservices architecture?

You can, but it’s not ideal. WF is designed for long-running, stateful workflows, which can be hard to scale in microservices. Consider using a separate workflow service (e.g., Elsa Core hosted as a service) that communicates via messages.

What is the difference between a sequential and a state machine workflow?

A sequential workflow runs steps in a fixed order, with branches and loops. A state machine workflow defines states and transitions, and the workflow moves between states based on events. State machines are better for event-driven processes like order fulfillment.

Do I need a visual designer to use a workflow framework?

No. Many frameworks allow you to define workflows entirely in code. A visual designer is useful when non-developers need to create or modify workflows, but it adds complexity. For simple, code-only workflows, a fluent API like Workflow Core is sufficient.

How do I handle workflow versioning?

In WF, you can use WorkflowIdentity to distinguish versions and implement a strategy to route new instances to the latest version while completing old ones. In Elsa, you can version workflow definitions and set which version is published.

Can I use a workflow framework for human approval tasks?

Yes. Both WF and Elsa Core support bookmarks (WF) or activities that wait for external signals (Elsa). You can persist the workflow while waiting for a user to approve or reject, then resume it.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →