Awarious OfficePortal - HRMS Application

Difference between CodeActivity and NativeActivity in workflow-foundation?

0 votes
asked Jul 11, 2013 in Workflow Foundation by Susan

What are code activity and Native activity in workflow foundation? When should I use one over the other? What is the difference between these two activities?


1 Answer

+1 vote
answered Jul 12, 2013 by Aadhira (1,215 points)
selected Jul 12, 2013 by administrator
Best answer

Core unit of the workflow foundation is Activities. Because, the workflow itself an activity which will have multiple child activities. There are some built in common activities comes with .Net framework. But, workflow is basically to support your business process. Since Microsoft cannot provide all activites which are required for your business, you may need to create your own custom and reusable activities.Those custom activities can be created by deriving from “CodeActivity” or “NativeActivity”.

CodeActivity is a very simple activity. You may create Custom code activity, when want to do some action and complete the activity. Code activity will just provide override for the method “execute”. This method will be called whenever your custom activity is executed.

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 you want to implement workflow persistence service by creating “Bookmark”, then you can do it only if your 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.

Sample CodeActivity

public sealed class SendNotification : CodeActivity
 // Define an activity input argument of type string
 public InArgument<string> FromArg { get; set; }
 public InArgument<string> ToArg { get; set; }
 public InArgument<string> SubjectArg { get; set; }
 public InArgument<string> MessageArg { get; set; }

 // If your activity returns a value, derive from CodeActivity<TResult>
 // and return the value from the Execute method.
 protected override void Execute(CodeActivityContext context)
  // Obtain the runtime value of the Text input argument
  string from = context.GetValue(this.FromArg);
  string to = context.GetValue(this.ToArg);
  string subject = context.GetValue(this.SubjectArg);
  string message = context.GetValue(this.MessageArg);
  SmtpClient smtpClient = new SmtpClient("localhost");
  smtpClient.Send(from, to, subject, message);

Your answer


Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
site design / logo / content © 2013 - 2019