Called by the workflow runtime to execute an activity.
Namespace:
System.Workflow.ComponentModel
Assembly:
System.Workflow.ComponentModel (in System.Workflow.ComponentModel.dll)
Visual Basic (Declaration)
Protected Friend Overridable Function Execute ( _
executionContext As ActivityExecutionContext _
) As ActivityExecutionStatus
Dim executionContext As ActivityExecutionContext
Dim returnValue As ActivityExecutionStatus
returnValue = Me.Execute(executionContext)
protected internal virtual ActivityExecutionStatus Execute(
ActivityExecutionContext executionContext
)
protected public:
virtual ActivityExecutionStatus Execute(
ActivityExecutionContext^ executionContext
)
protected internal function Execute(
executionContext : ActivityExecutionContext
) : ActivityExecutionStatus
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 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
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;
}
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.
.NET Framework
Supported in: 3.5, 3.0
Reference