Note the differences between CodeActivity, NativeActivity and AsyncCodeActivity while creating a Custom Activity .
There are some built in common activities comes with .NET framework. But, workflow is basically to support the business process. Since Microsoft cannot provide all activities which are required for the business, it may be needed to create own custom and reusable activities. Those custom activities can be created by deriving from “CodeActivity” or “NativeActivity”.
CodeActivity is a very simple activity. Create Custom code activity, when it is required to do some action and complete the activity. CodeActivity will just provide override for the method “execute”. This method will be called whenever the custom activity is executed.
public abstract class CodeActivity : System.Activities.Activity
public sealed class MessageBox : CodeActivity
{
public InArgument Text{ get; set; }
protected override void Execute(CodeActivityContext context) {
System.Windows.Forms.MessageBox.Show(this.Text.Get(context));
}
}
For more details on CodeActivity .
NativeActivity provides more functionality and allows creating complex activities. Native Activity can schedule one or more different activities for execution which is not possible in Code Activity. Another important feature is, if it is required to implement workflow persistence service by creating “Bookmark”, then it can only be performed if the custom activity is derived from Native Activity. Apart from this, Native activity has access to all the features exposed by the workflow which includes Tracking.
public abstract class NativeActivity : System.Activities.Activity
For more details on NativeActivity Class .
AsyncCodeActivity manages asynchronous code activity execution from start to completion. This is an abstract class.
public abstract class AsyncCodeActivity : System.Activities.Activity
For more details on AsyncCodeActivity .