CodeActivity vs NativeActivity
When to use a CodeActivity and when NativeActivity?
Along with all the activity types available in WF 4 CodeActivity and NativeActivity are pretty powerful code based activities, which can be used to write your own custom code and create custom activities. When you create your own custom activity you have the option of either deriving from CodeAcitivity, or NativeActivity. So what is the basic difference between these two activity types?
Though these two activities look similar they have their differences.
1. Provides an Execute method that can be overridden to have your implementation. Also provides access to tracking, variables and arguments.
2. Use CodeActivity for simple Custom Activities
3. Use CodeActivity for Synchronous Activities
4. Use it when you need to execute in a single pulse of execution
5. Use it when you do not need to schedule other activities
6. Use it when you do not need to use advanced WF Runtime features
1. Provides all the features of the CodeActivity plus it lets you abort activity execution, cancel child activity execution, schedule activities, use bookmarks, activity actions and functions.
2. Use NativeActivity for complex Custom Activities
3. Use NativeActivity for long running Custom Activities
4. Use it when you need to execute in multiple pulses
5. Use it when you have to schedule other activities
6. Use NativeActivity when you need to use advanced WF Runtime features
Note: Do not Use NativeActivity to create activities that do not require capabilities of the WF Runtime – use CodeActivity Instead.
Here is a detailed description on using the NativeActivity. Click here
On Error Handling in NativeActivity. Click here
And for those who are wishing there were a Template for NativeActivity for Visual Studio 2010, here it is. Click Here
Note: The Other activity type that is available to create your Custom Activities is the AsyncCodeActivity