Activity.Execute(ActivityExecutionContext) Activity.Execute(ActivityExecutionContext) Activity.Execute(ActivityExecutionContext) Activity.Execute(ActivityExecutionContext) Method

Definition

Called by the workflow runtime to execute an activity.

protected public:
 virtual System::Workflow::ComponentModel::ActivityExecutionStatus Execute(System::Workflow::ComponentModel::ActivityExecutionContext ^ executionContext);
protected internal virtual System.Workflow.ComponentModel.ActivityExecutionStatus Execute (System.Workflow.ComponentModel.ActivityExecutionContext executionContext);
abstract member Execute : System.Workflow.ComponentModel.ActivityExecutionContext -> System.Workflow.ComponentModel.ActivityExecutionStatus
override this.Execute : System.Workflow.ComponentModel.ActivityExecutionContext -> System.Workflow.ComponentModel.ActivityExecutionStatus
Protected Friend Overridable Function Execute (executionContext As ActivityExecutionContext) As ActivityExecutionStatus

Parameters

Returns

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

Examples

The following code example shows an implementation of the Execute method. In this example, an Outlook email message is constructed and sent. This example is from the Outlook Workflow Wizard SDK sample. For more information, see Outlook 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");
            oMailItem.Send();
        }
    }
    else if (this.Parent.Parent is SequentialWorkflowActivity)
    {
        if ((this.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
        {
            MessageBox.Show("Process Auto-Reply for Email");
            oMailItem.Send();
        }
    }
    return ActivityExecutionStatus.Closed;
}
Protected Overrides Function Execute(ByVal executionContext As System.Workflow.ComponentModel.ActivityExecutionContext) As System.Workflow.ComponentModel.ActivityExecutionStatus
    ' Create an Outlook Application object. 
    Dim outlookApp As Outlook.Application = New Outlook.Application()

    Dim oMailItem As Outlook._MailItem = CType(outlookApp.CreateItem(Outlook.OlItemType.olMailItem), Outlook._MailItem)
    oMailItem.MailTo = outlookApp.Session.CurrentUser.Address
    oMailItem.Subject = "Auto-Reply"
    oMailItem.Body = "Out of Office"

    Dim dummy As Activity

    If TypeOf Me.Parent.Parent Is ParallelActivity Then
        dummy = Me.Parent.Parent.Parent.Activities.Item(1)
        If Not (CType(dummy, DummyActivity).Title = "") Then
            MessageBox.Show("Process Auto-Reply for Email")
            oMailItem.Send()
        End If
    End If
    If TypeOf Me.Parent.Parent Is SequentialWorkflowActivity Then
        dummy = Me.Parent.Parent.Activities.Item(1)
        If Not (CType(dummy, DummyActivity).Title = "") Then
            MessageBox.Show("Process Auto-Reply for Email")
            oMailItem.Send()
        End If
    End If

    Return ActivityExecutionStatus.Closed
End Function

Remarks

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.

Applies to