Activity.Execute(ActivityExecutionContext) 方法

定义

由工作流运行时调用,用于执行活动。

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

参数

executionContext
ActivityExecutionContext

与此 ActivityExecutionContext 和执行关联的 Activity

返回

运行任务的 ActivityExecutionStatus,确定活动是保留执行状态,还是转换为关闭状态。

示例

下面的代码示例演示 Execute 方法的实现。 在此示例中,构造并发送 Outlook 电子邮件。 此示例摘自“Outlook 工作流向导”SDK 示例。 有关详细信息,请参阅 Outlook 工作流向导示例

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

注解

ActivityExecutionContext 用于获取关于当前运行的活动和工作流的信息,还可用于从运行时环境获取服务。

运行同步发生,当活动完成后或达到中间状态时,将控制返回到调用方。

适用于