Activity 類別

定義

警告

此 API 現已淘汰。

表示工作流程的基本建置組塊。Represents the fundamental building block of workflows. Activity 是所有活動的基底類別。Activity is the base class for all activities.

public ref class Activity : System::Workflow::ComponentModel::DependencyObject
[System.Drawing.ToolboxBitmap(typeof(System.Workflow.ComponentModel.Activity), "Design.Resources.Activity.png")]
[System.Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
[System.Workflow.ComponentModel.Compiler.ActivityCodeGenerator(typeof(System.Workflow.ComponentModel.Compiler.ActivityCodeGenerator))]
[System.Workflow.ComponentModel.Compiler.ActivityValidator(typeof(System.Workflow.ComponentModel.Compiler.ActivityValidator))]
[System.Workflow.ComponentModel.Serialization.RuntimeNameProperty("Name")]
public class Activity : System.Workflow.ComponentModel.DependencyObject
type Activity = class
    inherit DependencyObject
Public Class Activity
Inherits DependencyObject
繼承
衍生
屬性

範例

這個範例會定義用來傳送電子郵件的活動。This example defines an activity whose purpose is to send an email. 該活動會定義一個 Subject 屬性,這個屬性在其實作中使用相依性屬性。The activity defines one property, Subject, that uses a dependency property in its implementation. 其他屬性會以類似的方式定義。Other properties can be defined in a similar way. Execute 方法會經過覆寫,以便提供電子郵件傳送時使用的邏輯。The Execute method is overridden to provide the logic for sending the email. 如需完整範例, 請參閱傳送電子郵件活動範例For a complete example, see the Send Email Activity Sample.

public class SendEmail : Activity  
{  
    public static readonly DependencyProperty SubjectProperty =  
        DependencyProperty.Register("Subject", typeof(string), typeof(SendEmail));  
  
    public string Subject  
    {  
        get { return base.GetValue(SubjectProperty) as string; }  
        set { base.SetValue(SubjectProperty, value); }  
    }  
  
    // Define other properties...  
  
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)  
    {  
        // Logic to send the email goes here...  
        return ActivityExecutionStatus.Closed;  
    }  
}  

備註

注意

此資料討論已被汰換的類型及命名空間。This material discusses types and namespaces that are obsolete. 如需詳細資訊,請參閱 Windows Workflow Foundation 4.5 中即將淘汰的類型For more information, see Deprecated Types in Windows Workflow Foundation 4.5.

Activity 是工作流程的基本建置組塊。An Activity is the fundamental building block of workflows. Activity 定義一組屬性和事件,如任何類別,以及定義活動執行階段行為的執行邏輯。An Activity defines a set of properties and events, such as any class, along with execution logic that defines the activity's run-time behavior. 您可讓一組額外的元件與 Activity 產生關聯。A set of additional components can be associated with an Activity. 這些元件包括 (但不限於) 驗證器、程式碼產生器、自訂序列化程式和設計工具。These include, but are not limited to a validator, a code generator, custom serializers, and a designer.

所有的活動會共用在 Activity 基底類別上定義的通用屬性集。All activities share a common set of properties defined on the Activity base class. 每個 Activity 可透過延伸這個類別的方式,根據自己的需求來宣告本身的額外屬性。Each Activity can declare its own additional properties according to its requirements by extending this class. 由於 Activity 衍生自 DependencyObject,因此屬性可被定義為標準 CLR 屬性和相依性屬性。Because Activity derives from DependencyObject, properties can be defined as standard CLR properties and as dependency properties.

Activity 的執行邏輯會履行合約,此合約存在於任何 Activity 和工作流程執行階段之間。The execution logic of an Activity fulfills a contract that exists between any Activity and the workflow runtime. 您必須將任何 Activity 的執行邏輯以基本的意義製作成文件,讓使用 Activity 的工作流程開發人員知道其行為。You must document the execution logic of any Activity in a functional sense, so that a workflow developer who uses the Activity knows how it behaves. 對於將活動包含在工作流程中的工作流程開發人員而言,執行邏輯本身是隱藏的,因為執行邏輯是合約的一部分,強制存在於工作流程執行階段和 Activity 之間。The execution logic itself is hidden from the workflow developer who includes the activity in a workflow, because the execution logic is part of a contract that exists strictly between the workflow runtime and the Activity.

建構函式

Activity()

初始化 Activity 類別的新執行個體。Initializes a new instance of the Activity class.

Activity(String)

初始化 Activity 的同時,初始化 Name 類別的新執行個體。Initializes a new instance of the Activity class, while initializing the Name.

欄位

ActivityContextGuidProperty

DependencyProperty,表示與 Guid 關聯之 ActivityExecutionContextActivityThe DependencyProperty that represents the Guid of the ActivityExecutionContext that is associated with the Activity.

CancelingEvent

表示目標為 DependencyProperty 事件的 CancelingRepresents the DependencyProperty that targets the Canceling event.

ClosedEvent

表示目標為 DependencyProperty 事件的 ClosedRepresents the DependencyProperty that targets the Closed event.

CompensatingEvent

表示目標為 DependencyProperty 事件的 CompensatingRepresents the DependencyProperty that targets the Compensating event.

ExecutingEvent

表示 DependencyProperty,其目標為 Executing 事件,這個事件會在執行活動時發生。Represents the DependencyProperty that targets the Executing event, which occurs when the activity is executed.

FaultingEvent

DependencyProperty,表示 Faulting 事件。The DependencyProperty that represents the Faulting event.

StatusChangedEvent

表示目標為 DependencyProperty 事件的 StatusChangedRepresents the DependencyProperty that targets the StatusChanged event.

屬性

Description

取得或設定 Activity 的使用者定義描述。Gets or sets the user-defined description of the Activity.

DesignMode

取得值,這個值會指出這個執行個體是在設計模式或執行階段模式中。Gets the value that indicates whether this instance is in design or run-time mode.

(繼承來源 DependencyObject)
Enabled

取得或設定值,這個值會指出是否啟用這個執行個體進行執行和驗證。Gets or sets a value that indicates whether this instance is enabled for execution and validation.

ExecutionResult

取得最後嘗試要執行這個執行個體的 ActivityExecutionResultGets the ActivityExecutionResult of the last attempt to run this instance.

ExecutionStatus

取得這個執行個體的目前 ActivityExecutionStatusGets the current ActivityExecutionStatus of this instance.

IsDynamicActivity

取得有關活動是否執行於工作流程執行個體之預設 ActivityExecutionContext 內的資訊。Gets information about whether the activity is executing within the default ActivityExecutionContext of the workflow instance.

Name

取得或設定這個執行個體的名稱。Gets or sets the name of this instance. 這個名稱必須符合工作流程專案中所使用之程式語言的變數命名慣例。This name must conform to the variable naming convention of the programming language that is being used in the Workflow project.

Parent

取得含有這個 CompositeActivityActivityGets the CompositeActivity that contains this Activity.

ParentDependencyObject

取得 DependencyObject 圖形中的父代 DependencyObjectGets the parent DependencyObject in the DependencyObject graph.

(繼承來源 DependencyObject)
QualifiedName

取得活動的完整名稱。Gets the qualified name of the activity. 在工作流程執行個體中,完整的活動名稱永遠是唯一的。Qualified activity names are always unique in a workflow instance.

Site

取得或設定 SiteDependencyObject 元件的參考。Gets or sets a reference to the Site component of the DependencyObject.

(繼承來源 DependencyObject)
UserData

取得 IDictionary,它會將自訂資料與這個類別執行個體產生關聯。Gets an IDictionary that associates custom data with this class instance.

(繼承來源 DependencyObject)
WorkflowInstanceId

取得與執行個體相關聯的 GuidGets the Guid associated with the instance.

方法

AddHandler(DependencyProperty, Object)

加入 DependencyObject之事件的處理常式。Adds a handler for an event of a DependencyObject.

(繼承來源 DependencyObject)
Cancel(ActivityExecutionContext)

由工作流程執行階段呼叫,以取消執行目前執行的活動。Called by the workflow runtime to cancel execution of an activity that is currently executing.

Clone()

建立 Activity 的深層複本 (Deep Copy)。Creates a deep copy of the Activity.

Dispose()

釋放 DependencyObject 使用的所有資源。Releases all the resources used by the DependencyObject.

(繼承來源 DependencyObject)
Dispose(Boolean)

會釋放 Unmanaged 資源,並選擇性地釋放 DependencyObject 所使用的 Managed 資源。Releases the unmanaged resources and optionally releases the managed resources used by DependencyObject.

(繼承來源 DependencyObject)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Execute(ActivityExecutionContext)

由工作流程執行階段呼叫以執行活動。Called by the workflow runtime to execute an activity.

GetActivityByName(String)

傳回 Activity 的執行個體,其名稱是向執行於此執行個體之根活動下的活動全體集合要求而來的,該執行個體則位於工作流程內。Returns the instance of the Activity whose name is requested from the set of all activities running under the root activity of this instance, which is within the workflow.

GetActivityByName(String, Boolean)

傳回 Activity 的執行個體,如果第二個參數是 false,則要求其名稱的來源是在這個執行個體其 Activity 的根項目之下的所有活動集,如果第二個參數是 true,則來源是在目前 Activity 之下。Returns the instance of the Activity whose name is requested from the set of all activities under the root the Activity of this instance if the second parameter is false and under the current Activity if the second parameter is true.

GetBinding(DependencyProperty)

提供存取與特定 ActivityBind 相關聯的 DependencyPropertyProvides access to the ActivityBind associated with the specific DependencyProperty.

(繼承來源 DependencyObject)
GetBoundValue(ActivityBind, Type)

擷取 Object,其為 ActivityBind 的主體。Retrieves the Object that is the subject of an ActivityBind.

(繼承來源 DependencyObject)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetInvocationList<T>(DependencyProperty)

取得陣列,這個陣列包含指定 DependencyProperty 的委派。Gets an array that contains the delegates for the specified DependencyProperty.

(繼承來源 DependencyObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
GetValue(DependencyProperty)

提供存取所指定 DependencyProperty 的值。Provides access to the value of the designated DependencyProperty.

(繼承來源 DependencyObject)
GetValueBase(DependencyProperty)

提供對 DependencyProperty 其繫結物件的存取,並略過 GetValue(DependencyProperty) 覆寫。Provides access to the bound object of a DependencyProperty and bypasses the GetValue(DependencyProperty) override.

(繼承來源 DependencyObject)
HandleFault(ActivityExecutionContext, Exception)

在這個執行個體的執行內容中引發例外狀況時呼叫。Called when an exception is raised within the context of the execution of this instance.

Initialize(IServiceProvider)

由工作流程執行階段呼叫,以初始化建構新工作流程執行個體期間的活動。Called by the workflow runtime to initialize an activity during the construction of a new workflow instance. 這個方法在建構動態的 ActivityExecutionContext 期間呼叫。This method is called during the construction of a dynamic ActivityExecutionContext.

InitializeProperties()

在衍生類別中覆寫時,在相依性屬性上執行初始化。Performs initialization on dependency properties when overridden in a derived class.

(繼承來源 DependencyObject)
Invoke<T>(EventHandler<T>, T)

訂閱 EventHandler 並叫用該委派。Subscribes an EventHandler and invokes that delegate.

Invoke<T>(IActivityEventListener<T>, T)

訂閱 IActivityEventListener<T> 並叫用該委派。Subscribes an IActivityEventListener<T> and invokes that delegate.

IsBindingSet(DependencyProperty)

指出 DependencyProperty 的值是否已設定為繫結。Indicates whether the value of a DependencyProperty is set as a binding. 請參閱 SetBinding(DependencyProperty, ActivityBind)See SetBinding(DependencyProperty, ActivityBind).

(繼承來源 DependencyObject)
Load(Stream, Activity)

Activity 載入 Stream 的執行個體。Loads an instance of an Activity from a Stream.

Load(Stream, Activity, IFormatter)

使用還原序列化的自訂 Activity,從 Stream 載入 IFormatter 的執行個體。Loads an instance of an Activity from a Stream using the custom IFormatter for deserialization.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
MetaEquals(DependencyObject)

判斷這個 metapropertiesDependencyObjectmetaproperties是否相等於參數化 DependencyObject 的 。Determines whether the metaproperties of this DependencyObject equals the metaproperties of the parameterized DependencyObject.

(繼承來源 DependencyObject)
OnActivityExecutionContextLoad(IServiceProvider)

每當載入 ActivityExecutionContext 時,由工作流程執行階段呼叫。Called by the workflow runtime whenever an ActivityExecutionContext is loaded. 例如,在建立 ActivityExecutionContext 期間,以及每次當從持續性儲存體載入工作流程執行個體時具體化 ActivityExecutionContext 時,呼叫這個方法。For example, this method is called during the creation of an ActivityExecutionContext as well as every time the ActivityExecutionContext is reincarnated when a workflow instance is loaded from persistent storage.

OnActivityExecutionContextUnload(IServiceProvider)

每當卸載 ActivityExecutionContext 時,由工作流程執行階段呼叫。Called by the workflow runtime whenever an ActivityExecutionContext is unloaded. 例如,在完成 ActivityExecutionContext 期間,以及每次當工作流程執行個體執行時卸載 ActivityExecutionContext 時,呼叫這個方法。For example, this method is called during completion of an ActivityExecutionContext as well as every time the ActivityExecutionContext is unloaded when a workflow instance is persisted.

OnClosed(IServiceProvider)

當活動轉換到已關閉狀態時,由工作流程執行階段呼叫。Called by the workflow runtime as part of the activity's transition to the closed state.

RaiseEvent(DependencyProperty, Object, EventArgs)

引發與指定相依性屬性相關聯的 EventRaises an Event associated with the specified dependency property.

RaiseGenericEvent<T>(DependencyProperty, Object, T)

引發與所參考 DependencyProperty 相關聯的事件。Raises the event associated with the referenced DependencyProperty.

RegisterForStatusChange(DependencyProperty, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>)

註冊狀態變更事件的指定 DependencyPropertyRegisters the specified DependencyProperty for the status change event.

RemoveHandler(DependencyProperty, Object)

EventHandler 從相關聯的 DependencyProperty 移除。Removes an EventHandler from an associated DependencyProperty.

(繼承來源 DependencyObject)
RemoveProperty(DependencyProperty)

DependencyPropertyDependencyObject 中移除。Removes a DependencyProperty from the DependencyObject.

(繼承來源 DependencyObject)
Save(Stream)

Activity 寫入保存性 (Persistence) 的 StreamWrites the Activity to a Stream for persistence.

Save(Stream, IFormatter)

使用為序列化提供的自訂 Activity,將 Stream 寫入 IFormatter 以供保存。Writes the Activity to a Stream for persistence using the custom IFormatter provided for serialization.

SetBinding(DependencyProperty, ActivityBind)

設定所指定 ActivityBindDependencyPropertySets the ActivityBind for the specified DependencyProperty.

(繼承來源 DependencyObject)
SetBoundValue(ActivityBind, Object)

設定目標 ActivityBind 的值。Sets the value of the target ActivityBind.

(繼承來源 DependencyObject)
SetReadOnlyPropertyValue(DependencyProperty, Object)

設定唯讀的 DependencyProperty 其值。Sets the value of a DependencyProperty, which is read-only.

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

DependencyProperty 的值設定給物件。Sets the value of the DependencyProperty to the object.

(繼承來源 DependencyObject)
SetValueBase(DependencyProperty, Object)

DependencyProperty 的值設定為指定的 Object,略過 SetValue(DependencyProperty, Object)Sets the value of the DependencyProperty to the specified Object, bypassing the SetValue(DependencyProperty, Object).

(繼承來源 DependencyObject)
ToString()

提供代表這個執行個體的字串。Provides a string that represents this instance.

TrackData(Object)

通知執行階段追蹤基礎結構關於暫止追蹤的資訊。Informs the run-time tracking infrastructure of pending tracking information.

TrackData(String, Object)

通知執行階段追蹤基礎結構關於暫止追蹤的資訊。Informs the run-time tracking infrastructure of pending tracking information.

Uninitialize(IServiceProvider)

在衍生類別中覆寫時,依據活動的服務提供者提供還原初始化。When overridden in a derived class, provides un-initialization by a service provider for the activity.

UnregisterForStatusChange(DependencyProperty, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>)

解除註冊狀態變更事件的指定 DependencyPropertyUn-registers the specified DependencyProperty for the status change event.

事件

Canceling

取消執行活動時發生。Occurs when the activity execution is canceled.

Closed

發生於 Activity 已完成執行時。Occurs when an Activity has completed execution.

Compensating

發生於在 Activity 上執行補償方法時。Occurs when running a compensation method on the Activity.

Executing

發生於執行 Activity 時。Occurs when the Activity is run.

Faulting

在執行個體執行期間引發例外狀況時發生。Occurs when an exception is raised during the running of the instance.

StatusChanged

發生於正在執行之 ActivityExecutionStatusActivity 變更時。Occurs when the ActivityExecutionStatus of a running Activity changes.

明確介面實作

IComponent.Disposed

表示處理元件 Disposed 事件的方法。Represents the method that handles the Disposed event of a component.

(繼承來源 DependencyObject)

適用於