اقرأ باللغة الإنجليزية تحرير

مشاركة عبر


Activity.Execute(ActivityExecutionContext) Method

Definition

Called by the workflow runtime to execute an activity.

C#
protected internal virtual System.Workflow.ComponentModel.ActivityExecutionStatus Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext);

Parameters

executionContext
ActivityExecutionContext

The ActivityExecutionContext to associate with this Activity and execution.

Returns

The ActivityExecutionStatus of the run task, which determines whether the activity remains in the executing state, or transitions to the closed state.

Examples

The following code example shows an implementation of the Execute method. In this example, an Outlook email message is constructed and sent. This example is from the Outlook Workflow Wizard SDK sample. For more information, see Outlook Workflow Wizard Sample.

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;
}

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.

Applies to

منتج الإصدارات
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1