views:

752

answers:

2

I'm evaluating the new version of Workflow Foundation (4.0), but I'm a bit confused about custom activities. I'm using the Beta 1 bits.

I believe that if I want to create a custom activity I should extend WorkflowElement, and if I want my custom activity to hold other activities I should extend Activity. However, WorkflowElement appears to have lots of abstract internal methods which I can't override.

My co-worker believes custom non-container (i.e., doesn't hold other activities) activities should extend CodeActivity. But in the last version of WF, CodeActivities weren't a base class, they were activities that executed a method in the parent workflow.

What's the latest word on this? What should I be using for the base class for my custom activities in Workflow 4.0?

+1  A: 

Was still digging and found this:

  • Activity: Used when creating a composite activity – an activity who’s execution is entirely expressed as a composition of other activities. Activities that you create from the Activity type can be designed in a declarative fashion (using XAML) and don’t allow for any imperative code. From a conceptual perspective, when authoring a “workflow” (in this case, defined as connecting a series of activities together), you are essentially authoring a derived “Activity” class.
  • CodeActivity: Used when creating an activity that implements a custom Execute method, and is designed for short-running chunks of work.
  • NativeActivity: Used when creating an activity that has full access to the core of the WF runtime features such scheduling child activities and manipulating bookmarks. This is intended as the type of last resort, and we don’t expect many folks to inherit from this type.
  • WorkflowElement: This is the abstract base type that all activities derive from.

Source: http://blogs.msdn.com/endpoint/archive/2009/05/01/the-road-to-4-wf-changes-between-beta-1-and-ctp.aspx


NativeActivity. CodeActivity is NA but for wimps. Also, there are async versions of these.

Will
Cant really edit but thought I would add AsyncCodeActivity Class. http://msdn.microsoft.com/en-us/library/system.activities.asynccodeactivity.aspx Essentially its the Async version of a code activity and, the generics versions of each I.E CodeActivity<TResult>, NativeActivity<TResult> etc... when in need of returning a value from the activity.
Terrance
@Ter dude this was back in beta1 days.
Will
Maybe so but Complete info is complete and that seems to be a common question so why not have a complete common answer. I would think the question would be to local if in the title you put "beta" but because its just 4.0 I would think its more relevant
Terrance
A: 

Extending from CodeActivity gives you the basic functionality that you would need inside a WF instance. This is the most simple approach.

If you wish do change the scheduling of WF execution (schedule another activity depending of some conditions, or schedule a "Wait" by creating Bookmarks) you will need to extend from NativeActivity.

Isaac Yuen