.NET Framework Class Library
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)
Syntax

Visual Basic (Declaration)
Protected Friend Overridable Function Execute ( _
    executionContext As ActivityExecutionContext _
) As ActivityExecutionStatus
Visual Basic (Usage)
Dim executionContext As ActivityExecutionContext
Dim returnValue As ActivityExecutionStatus

returnValue = Me.Execute(executionContext)
C#
protected internal virtual ActivityExecutionStatus Execute(
    ActivityExecutionContext executionContext
)
Visual C++
protected public:
virtual ActivityExecutionStatus Execute(
    ActivityExecutionContext^ executionContext
)
JScript
protected internal function Execute(
    executionContext : ActivityExecutionContext
) : ActivityExecutionStatus

Parameters

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.
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.

Examples

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, see Outlook Workflow Wizard Sample.

Visual Basic
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
C#
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;
}
.NET Framework Security

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Tags :


Page view tracker