This topic has not yet been rated Rate this topic

WorkflowInstance Class

Represents a workflow instance.

System.Object
  System.Workflow.Runtime.WorkflowInstance

Namespace:  System.Workflow.Runtime
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)
public sealed class WorkflowInstance

The WorkflowInstance type exposes the following members.

  Name Description
Public property InstanceId Gets the unique identifier for the workflow instance.
Public property WorkflowRuntime Gets the WorkflowRuntime for this workflow instance.
Top
  Name Description
Public method Abort Aborts the workflow instance.
Public method ApplyWorkflowChanges Applies changes to the workflow instance specified by the WorkflowChanges object.
Public method EnqueueItem Posts a message to the specified workflow queue synchronously.
Public method EnqueueItemOnIdle Posts a message to the specified workflow queue when the workflow is idle. EnqueueItemOnIdle waits until the workflow reaches an idle point and enqueues after verifying that the workflow scheduler is idle (that is, no active operation is being executed).
Public method Equals Returns a value that indicates whether the specified object is equal to the WorkflowInstance. (Overrides Object.Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Returns the hash code for this workflow instance. (Overrides Object.GetHashCode.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method GetWorkflowDefinition Retrieves the root activity for this workflow instance.
Public method GetWorkflowNextTimerExpiration Returns the next point in time that this WorkflowInstance is scheduled to be delivered a timer message.
Public method GetWorkflowQueueData Gets a collection of WorkflowQueueInfo objects that contains the pending items and subscribed activities for the workflow queues associated with this workflow instance.
Public method Load Loads a previously unloaded workflow instance.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ReloadTrackingProfiles Reload the tracking profiles for this workflow instance.
Public method Resume Resumes execution of a previously suspended workflow instance.
Public method Start Starts the execution of the workflow instance.
Public method Suspend Suspends the workflow instance.
Public method Terminate Terminates the workflow instance in a synchronous manner.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method TryUnload Unloads the workflow instance from memory to the persistence store when the instance is suspended or idle.
Public method Unload Unloads the workflow instance from memory to the persistence store. This call blocks until after the currently scheduled work is finished, or the end of a transaction scope.
Top

The WorkflowInstance class exposes methods and properties that can be used to control the execution of a workflow instance; it is essentially a proxy to the actual workflow instance used by the workflow runtime engine. A host or a service can instruct the workflow runtime engine to perform actions on a workflow instance by calling the appropriate methods that are contained in the WorkflowInstance class. If the requested action is not valid, for example, if the host calls Load on a workflow instance that has already completed, the workflow runtime engine will raise an appropriate exception.

Note Note

If a workflow instance becomes unresponsive because a call on the host application does not return, the only way to recover the instance is to restart the runtime. However, if the instance has been forcibly unloaded, aborted, or suspended, it can be continued by calling the WorkflowInstance.Resume method.

The following code example demonstrates how you can create and start a WorkflowInstance in a workflow host. The code creates an instance of the WorkflowRuntime, adds services to the runtime, and then demonstrates the recommended way to create a WorkflowInstance object. The code initializes WorkflowInstance by calling the CreateWorkflow method and passing the previously created type to it. The WorkflowInstance is started with the Start method call.

This code example is part of the Canceling a Workflow SDK sample from the Program.cs file. For more information, see Canceling a Workflow.


Type type = typeof(SampleWorkflow1);
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
workflowInstance.Start();


.NET Framework

Supported in: 4, 3.5, 3.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

This type is thread safe.

Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ