Windows Workflow Changes Direction: Write New Workflows with .NET 4.0 in Mind

You can tweak your 3.0/3.5 workflows to make the transition to Windows Workflow Foundation (WF) 4.0 a little easier. These guidelines limit the scenarios in which there's no corresponding feature in 4.0.

  1. Create custom activities. Create custom activities instead of code-beside logic in a CodeActivity. There's no CodeActivity in WF 4.0. Remember that the custom activity model also changes, so it's best to move complex code out of the activity into utility libraries or services.
  2. Scope tightly. 4.0 variables are more constrained than 3.0 dependency properties. They no longer use the property bag/dependency property approach but instead are scoped vertically. Choose a variable in a parent activity set retrieved by child activities rather than directly retrieving data from a sibling activity.
  3. Use Windows Communication Foundation (WCF) messaging when there's a choice. The Data Exchange Service (DES) model goes away in WF 4.0: there's no external event model; external communications is through WCF; and WCF interactions will be considerably easier in WF 4.0. For workflows that might transition to 4.0, write them in WF 3.5, and use the Send and Receive activities. However, if you don't yet have WCF in your application or organization, implementing it in WCF 3.5 may be onerous. In this case, use events, and assume you'll rewrite around the new communications approach.
  4. Perform initialization logic in the Activity.Execute method. The signaling model changes in WF 4.0, and there's no Activity.Initialize event. Any setup should be done in the Activity.Execute method.
  5. Use WorkflowInstance.EnqueueOnIdle for queuing. If you're doing manual queuing, which is relatively uncommon, you should use the EnqueueOnIdle method, as this will be the only queuing model supported going forward.
  6. Be careful with data. The tracking and persistence databases are likely to change significantly between 3.5 and 4.0. Holding data only in tracking is hazardous, unless you prepare a strategy for extracting data, such as when a workflow completes. If you're using rules for simple data retrieval for values that should be set outside the workflow, consider holding this data in a configuration file or database. Note that these are preliminary suggestions. Check out my blog for pointers towards Microsoft's formal guidance, as well as tools (as they become available) that will help you transition workflows.
comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube