This documentation is archived and is not being maintained.

Activity.Execute Method

Called by the workflow runtime to execute an activity.

Namespace:  System.Workflow.ComponentModel
Assembly:  System.Workflow.ComponentModel (in System.Workflow.ComponentModel.dll)

protected internal virtual ActivityExecutionStatus Execute(
	ActivityExecutionContext executionContext


Type: System.Workflow.ComponentModel.ActivityExecutionContext
The ActivityExecutionContext to associate with this Activity and execution.

Return Value

Type: System.Workflow.ComponentModel.ActivityExecutionStatus
The ActivityExecutionStatus of the run task, which determines whether the activity remains in the executing state, or transitions to the closed state.

The ActivityExecutionContext is used to get information about the currently running activity and workflow, and is also used to obtain services from the runtime environment.

The running occurs synchronously, returning control to the caller when the activity is completed or reaches an intermediate state.

The following code example shows an implementation of the Execute method. In this example, an Outlook e-mail message is constructed and sent. This example is from the Outlook Workflow Wizard SDK sample. For more information, seeOutlook Workflow Wizard Sample.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
    // Create an Outlook Application object. 
    Outlook.Application outlookApp = new Outlook.Application();

    Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
    oMailItem.To = outlookApp.Session.CurrentUser.Address;
    oMailItem.Subject = "Auto-Reply";
    oMailItem.Body = "Out of Office";

    //adds it to the outbox  
    if (this.Parent.Parent is ParallelActivity)
        if ((this.Parent.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
            MessageBox.Show("Process Auto-Reply for Email");
    else if (this.Parent.Parent is SequentialWorkflowActivity)
        if ((this.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
            MessageBox.Show("Process Auto-Reply for Email");
    return ActivityExecutionStatus.Closed;

.NET Framework

Supported in: 4, 3.5, 3.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.