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 )
Parameters
- executionContext
- Type: System.Workflow.ComponentModel.ActivityExecutionContext
The ActivityExecutionContext to associate with this Activity and execution.
Return Value
Type: System.Workflow.ComponentModel.ActivityExecutionStatusThe 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, 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; }
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.