Activity.Execute(ActivityExecutionContext) 方法
定义
由工作流运行时调用,用于执行活动。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
参数
- executionContext
- ActivityExecutionContext
与此 ActivityExecutionContext 和执行关联的 Activity。The ActivityExecutionContext to associate with this Activity and execution.
返回
运行任务的 ActivityExecutionStatus,确定活动是保留执行状态,还是转换为关闭状态。The ActivityExecutionStatus of the run task, which determines whether the activity remains in the executing state, or transitions to the closed state.
示例
下面的代码示例演示 Execute 方法的实现。The following code example shows an implementation of the Execute method. 在此示例中,将构造并发送 Outlook 电子邮件。In this example, an Outlook email message is constructed and sent. 此示例摘自“Outlook 工作流向导”SDK 示例。This example is from the Outlook Workflow Wizard SDK sample. 有关详细信息,请参阅 Outlook 工作流向导示例。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
注解
ActivityExecutionContext 用于获取关于当前运行的活动和工作流的信息,还可用于从运行时环境获取服务。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.