When to use Windows Workflow Foundation?

71,750

Solution 1

You may need WF only if any of the following are true:

  1. You have a long-running process.
  2. You have a process that changes frequently.
  3. You want a visual model of the process.

For more details, see Paul Andrew's post: What to use Windows Workflow Foundation for?

Please do not confuse or relate WF with visual programming of any kind. It is wrong and can lead to very bad architecture/design decisions.

Solution 2

Never. You will probably regret it:

  • Steep learning curve
  • Difficult to debug
  • Difficult to maintain
  • Doesn't provide enough power, flexibility, or productivity gain to justify its use
  • Can and will corrupt application state that cannot be recovered

The only time I could ever conceive of using WF is if I wanted to host the designer for an end-user and probably not even then.

Trust me, nothing will ever be as straightforward, powerful, or flexible as the code that you write to do exactly what you need it to do. Stay away from WF.

Of course, this is only my opinion, but I think it's a damn good one. :)

Solution 3

The code generated by WF is nasty. The value that WF brings is in the visual representation of the system, although I have yet to see anything (6-7 projects at work now with WF that i've been involved with) where I would not have preferred a simpler hand coded project.

Solution 4

In general, if you do not need the persistence and tracking features (which in my opinion are the main features), you shouldn't use Workflow Foundation.

Here are the advantages and disadvantages of Workflow Foundation I gathered from my experience:

Advantages

  • Persistence: If you're going to have many long running processes (think days, weeks, months), then Workflows are great for this. Idle workflow instances are persisted to the database so it doesn't use up memory.
  • Tracking: WF provides the mechanism to track each activity executed in a workflow
  • *Visual Designer: I put this as a *, because I think this is really only useful for marketing purposes. As a developer, I prefer to write code rather than snapping things together visually. And when you have a non-developer making workflows, you often end up with a huge confusing mess.

Disadvantages

  • Programming Model: You're really limited in programming features. Think about all the great features you have in C#, then forget about them. Simple one or two line statements in C# becomes a fairly large block activities. This is particularly a pain for input validation. Having said that, if you're really careful to keep only high-level logic in workflows, and everything else in C#, then it might not be a problem.
  • Performance: Workflows use up a large amount of memory. If you're deploying a lot of workflows on a server, make sure you have tons of memory. Also be aware that workflows are much slower than normal C# code.
  • Steep learning curve, hard to debug: As mentioned above. You're going to spend a lot of time figuring out how to get things to work, and figuring out the best way to do something.
  • Workflow Version Incompatibility: If you deploy a workflow with persistence, and you need to make updates to the workflow, the old workflow instances are no longer compatible. Supposedly this is fixed in .NET 4.5.
  • You have to use VB expressions (.NET 4.5 allows for C# expressions).
  • Not flexible: If you need some special or specific functionality not provided by Workflow Foundation, prepare for a lot of pain. In some cases, it might not even be possible. Who knows until you try? There's a lot of risk here.
  • WCF XAML services without interfaces: Normally with WCF services, you develop against an interface. With WCF XAML Services, you cannot ensure a WCF XAML Service has implemented everything in an interface. You don't even need to define an interface. (as far as I know...)

Solution 5

The major reason I've found for using workflow foundation is how much it brings you out of the box in terms of tracking and persistence. It's very easy to get the persistence service up and running, which brings reliability and load distribution between multiple instances and hosts.

On the other hand, just like forms apps, the code patterns that the workflow designer pushes you towards are bad. But you can avoid problems by writing no code in the workflow and delegating all work to other classes, which can be organized and unit tested more gracefully than the workflow. Then you get the cool visual aspect of the designer without the cruft of spaghetti code behind.

Share:
71,750

Related videos on Youtube

Sumrak
Author by

Sumrak

Developing in .NET

Updated on March 07, 2020

Comments

  • Sumrak
    Sumrak over 4 years

    Some things are easier to implement just by hand (code), but some are easier through WF. It looks like WF can be used to create (almost) any kind of algorithm. So (theoretically) I can do all my logic in WF, but it's probably a bad idea to do it for all projects.

    In what situations is it a good idea to use WF and when will it make things harder then they have to be? What are pros and cons/cost of WF vs. coding by hand?

    • sclarson
      sclarson over 9 years
      It seems worth noting that a completely re-written for the 4.0 release which came out after these answers.
  • Dour High Arch
    Dour High Arch over 12 years
    Too bad regular web services and applications don't have .config files, can't read databases, nor read XML nor local files that contain rules, without recompiling. Oh wait...
  • danfromisrael
    danfromisrael over 12 years
    -1 i respect your opinion on this but would much appriciate a professional explenation of the reason. i cant see how this kind of an answer helps anyone
  • MsBao
    MsBao over 12 years
    I wrote this answer on a day that I was angry at WF4. I'll update my answer with the issues I have faced.
  • ivorykoder
    ivorykoder about 11 years
    What is the measuring unit for long-running process?
  • lobsterism
    lobsterism almost 11 years
    @ivorykoder "processes" (really workflows) that can survive restarts of the server hosting it.
  • Kevin DeVoe
    Kevin DeVoe almost 11 years
    We inherited a half completed project from a consultant which used WF as its backbone. It was prone to errors, corrupted workflows that can't be restarted, an archaic versioning system that requires a complete duplicate of the workflow for any minor changes, horrific generated code, and such a delicate code that you have to handle it with kid gloves. After 6 months of yellow screens of death we scrapped the entire WF and used xml instead. Best decision we ever made.
  • David Tansey
    David Tansey over 10 years
    The phrase: "Doesn't provide enough power, flexibility, or productivity gain to justify its use" says plenty enough for me. Thank you for that.
  • MsBao
    MsBao over 10 years
    Haters need to explain their hate.
  • Mick
    Mick almost 10 years
    If I had requirements that only satisfied #1, that wouldn't be enough for me to choose WF. However if the requirements included #2 and/or #3, that would be a much stronger case for using WF.
  • MsBao
    MsBao over 9 years
    I can't resist: You may need WF only if any of the following are true: false.
  • Sven
    Sven almost 9 years
    Most of your disadvantages are simply not true, maybe you are not familiar enough with WF. WF is very flexible. It let's you write custom activities (code activities) that you can reuse in any scenario. It's up to you to write reusable activities. Imagine you would be able to provide a GUI (WPF app with Workflow Designer Host) to Business Consultants along with a toolset of activities. Now they can change and re-arrange business logic in their needs and they don't require developers and even compile a new application.
  • Sven
    Sven almost 9 years
    This answer is completely wrong. You should read more articles about WF and then think about your answer once again. For example: WF is easy to debug, you can set breakpoints in the Visual Designer. My opinion is: WF is very powerful, you can create a toolset for your company managers so they will be able to make changes in the business logic on their own. Then you don't even need a developer.
  • Sven
    Sven almost 9 years
    But I have to admit that initial version of WF 3.5 the designer was really horrible.
  • Mas
    Mas almost 9 years
    Now imagine the Business Consultants have to use your self-hosted designer, but without Intellisense! Either roll your own or you have to use Visual Studio. I also think it will be difficult for Business Consultants to even understand some of the concepts such as compensation, cancellation, exception handling. Also any logic that is event remotely complex will result in a giant workflow that becomes unmaintainable (oh, and you'll need tons of ram to edit such workflows). You are right though, with carefully crafted custom activities do provide a fair amount of flexibility.
  • MsBao
    MsBao almost 9 years
    @Sven My opinion isn't wrong! Yours is! :P
  • Phill
    Phill almost 5 years
    I absolutely HATE Windows Workflow Foundation. But this answer is pretty bad.