Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

WorkflowApplication Class

Provides a host for a single instance of a workflow.

Namespace:  System.Activities
Assembly:  System.Activities (in System.Activities.dll)
'Declaration
Public NotInheritable Class WorkflowApplication _
	Inherits WorkflowInstance

The WorkflowApplication type exposes the following members.

  NameDescription
Public methodWorkflowApplication(Activity)Creates a new instance of the WorkflowApplication class with the specified workflow definition.
Public methodWorkflowApplication(Activity, IDictionary(Of String, Object))Creates a new instance of the WorkflowApplication class that uses the specified workflow definition and argument values.
Top
  NameDescription
Public propertyAbortedGets or sets the Action(Of T) that is invoked when the workflow instance is aborted.
Public propertyCompletedGets or sets the Action(Of T) that is invoked when the workflow instance completes.
Protected propertyControllerGets the WorkflowInstance.WorkflowInstanceControl instance for this WorkflowInstance. (Inherited from WorkflowInstance.)
Public propertyExtensionsGets the collection of extensions for the current workflow instance.
Public propertyHostEnvironmentGets or sets the root environment for the workflow instance’s arguments and variables. (Inherited from WorkflowInstance.)
Public propertyIdGets the 128-bit GUID identifier of the current workflow application instance. (Overrides WorkflowInstance.Id.)
Public propertyIdleGets or sets the Action(Of T) that is invoked when the current workflow instance becomes idle.
Public propertyInstanceStoreGets or sets an object that provides access to the persisted state of the current instance of the workflow application.
Protected propertyIsReadOnlyGets a value that indicates whether the workflow instance has been initialized. (Inherited from WorkflowInstance.)
Public propertyOnUnhandledExceptionGets or sets the Func(Of T, TResult) that is invoked when the current workflow instance encounters an unhandled exception.
Public propertyPersistableIdleGets or sets the ActivityFunc that is invoked when the current workflow instance is idle and can be persisted.
Protected propertySupportsInstanceKeysGets a value that indicates whether the host supports the association of InstanceKeys with a run-time instance. (Inherited from WorkflowInstance.)
Public propertySynchronizationContextGets or sets the SynchronizationContext used for scheduling the workflow instance. (Inherited from WorkflowInstance.)
Public propertyUnloadedGets or sets the Action(Of T) that is invoked when the current workflow unloads.
Public propertyWorkflowDefinitionGets the workflow definition of the workflow instance. (Inherited from WorkflowInstance.)
Top
  NameDescription
Public methodAbortNotifies the workflow runtime that this workflow instance should abort.
Public methodAbort(String)Notifies the workflow runtime that this workflow instance should abort for the specified reason.
Public methodAddInitialInstanceValuesSpecifies instance metadata values that are included with the first persistence of a new instance.
Public methodBeginCancel(AsyncCallback, Object)Cancels a workflow instance asynchronously using the specified AsyncCallback and user-provided state.
Public methodBeginCancel(TimeSpan, AsyncCallback, Object)Cancels a workflow instance asynchronously using the specified time-out interval, AsyncCallback, and user-provided state.
Public methodBeginLoad(Guid, AsyncCallback, Object)Loads a workflow asynchronously from an instance store using the specified instance identifier, callback method, and user-provided state.
Public methodBeginLoad(Guid, TimeSpan, AsyncCallback, Object)Loads a workflow asynchronously from an instance store using the specified instance identifier, timeout period, callback method, and user-provided state.
Public methodBeginLoadRunnableInstance(AsyncCallback, Object)Initiates an operation to load a runnable workflow instance from the InstanceStore.
Public methodBeginLoadRunnableInstance(TimeSpan, AsyncCallback, Object)Initiates an operation to load a runnable workflow instance from the InstanceStore using the specified time-out interval.
Public methodBeginPersist(AsyncCallback, Object)Persists a workflow instance to an instance store asynchronously using the specified callback method and user-provided state.
Public methodBeginPersist(TimeSpan, AsyncCallback, Object)Persists a workflow instance to an instance store asynchronously using the specified time-out interval, callback method, and user-provided state.
Public methodBeginResumeBookmark(Bookmark, Object, AsyncCallback, Object)Initiates an operation to resume a bookmark using the specified value, callback method, and state.
Public methodBeginResumeBookmark(String, Object, AsyncCallback, Object)Initiates an asynchronous operation to resume the bookmark with the specified name, using the specified value, callback method, and state. The bookmark to be resumed is previously created by an activity within the workflow instance.
Public methodBeginResumeBookmark(Bookmark, Object, TimeSpan, AsyncCallback, Object)Initiates an operation to resume a bookmark using the specified value, time-out interval, callback method, and state.
Public methodBeginResumeBookmark(String, Object, TimeSpan, AsyncCallback, Object)Initiates an asynchronous operation to resume the bookmark with the specified name, using the specified value, time-out interval, callback method, and state. The bookmark to be resumed is previously created by an activity within the workflow instance.
Public methodBeginRun(AsyncCallback, Object)Starts or resumes a workflow instance asynchronously using the specified callback method and user-provided state.
Public methodBeginRun(TimeSpan, AsyncCallback, Object)Starts or resumes a workflow instance asynchronously using the specified time-out interval, callback method, and user-provided state.
Public methodBeginTerminate(Exception, AsyncCallback, Object)Terminates a workflow instance asynchronously using the specified exception, callback method, and user-provided state.
Public methodBeginTerminate(String, AsyncCallback, Object)Terminates a workflow instance asynchronously using the specified error message, callback method, and user-provided state.
Public methodBeginTerminate(Exception, TimeSpan, AsyncCallback, Object)Terminates a workflow instance asynchronously using the specified exception, time-out interval, callback method, and user-provided state.
Public methodBeginTerminate(String, TimeSpan, AsyncCallback, Object)Terminates a workflow instance asynchronously using the specified error message, time-out interval, callback method, and user-provided state.
Public methodBeginUnload(AsyncCallback, Object)Persists and disposes a workflow instance asynchronously using the specified callback method and user-provided state.
Public methodBeginUnload(TimeSpan, AsyncCallback, Object)Persists and disposes a workflow instance asynchronously using the specified time-out interval, callback method, and user-provided state.
Public methodCancelCancels the workflow instance.
Public methodCancel(TimeSpan)Cancels the workflow instance using the specified time-out interval.
Protected methodDisposeExtensionsCalls Dispose on all extensions that implement IDisposable. (Inherited from WorkflowInstance.)
Public methodEndCancelWaits for the pending asynchronous cancel operation to complete.
Public methodEndLoadWaits for the pending asynchronous load operation to complete.
Public methodEndLoadRunnableInstanceWaits for the asynchronous load runnable instance operation to complete.
Public methodEndPersistWaits for the pending asynchronous persist operation to complete.
Public methodEndResumeBookmarkWaits for a bookmark resume operation to complete.
Public methodEndRunWaits for the pending asynchronous run operation to complete.
Public methodEndTerminateWaits for the pending asynchronous terminate operation to complete.
Public methodEndUnloadWaits for the pending asynchronous unload operation to complete.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetBookmarksReturns the collection of bookmarks for the workflow instance.
Public methodGetBookmarks(TimeSpan)Returns the collection of bookmarks for the workflow instance using the specified time-out interval.
Protected methodGetExtension(Of T)Returns an extension of the specified type. (Inherited from WorkflowInstance.)
Protected methodGetExtensions(Of T)Returns all extensions found for the specified type. (Inherited from WorkflowInstance.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodInitialize(Object)Called by the host to initialize the workflow instance with the workflow run-time state. (Inherited from WorkflowInstance.)
Protected methodInitialize(IDictionary(Of String, Object), IList(Of Handle))Called by the host to initialize the workflow instance with the argument values and execution properties. (Inherited from WorkflowInstance.)
Public methodLoad(Guid)Loads the specified workflow instance into memory from an instance store.
Public methodLoad(Guid, TimeSpan)Loads the specified workflow instance into memory from an instance store using the specified time-out interval.
Public methodLoadRunnableInstanceLoads a runnable workflow instance from the InstanceStore.
Public methodLoadRunnableInstance(TimeSpan)Loads a runnable workflow instance from the InstanceStore using the specified time-out interval.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnBeginAssociateKeysCalled by the workflow runtime to notify the host that new instance keys should be associated with this instance. (Inherited from WorkflowInstance.)
Protected methodOnBeginFlushTrackingRecordsAsynchronous call to ask host to flush pending tracking records to tracking participants. (Inherited from WorkflowInstance.)
Protected methodOnBeginPersistAsynchronous call to ask the host to persist the workflow. (Inherited from WorkflowInstance.)
Protected methodOnBeginResumeBookmarkCalled by the workflow runtime to notify the host that a resume bookmark operation is beginning. (Inherited from WorkflowInstance.)
Protected methodOnDisassociateKeysCalled by the workflow runtime to notify the host that a certain set of instance keys should no longer be associated with this instance. (Inherited from WorkflowInstance.)
Protected methodOnEndAssociateKeysCalled by the workflow runtime to notify the host that an associate keys operation is complete. (Inherited from WorkflowInstance.)
Protected methodOnEndFlushTrackingRecordsCalled by the workflow runtime to notify the host when the flush tracking records operation is complete. (Inherited from WorkflowInstance.)
Protected methodOnEndPersistCalled by the workflow runtime to notify the host that a persist operation is complete. (Inherited from WorkflowInstance.)
Protected methodOnEndResumeBookmarkCalled by the workflow runtime to notify the host that a resume bookmark operation is complete. (Inherited from WorkflowInstance.)
Protected methodOnNotifyPausedCalled by the workflow runtime to notify the host that the workflow instance has transitioned from the running state to the paused state. (Inherited from WorkflowInstance.)
Protected methodOnNotifyUnhandledExceptionCalled by the workflow runtime to notify the host an unhandled exception has occurred in the workflow instance. (Inherited from WorkflowInstance.)
Protected methodOnRequestAbortCalled by the workflow runtime to notify the host that an abort operation has been requested for the workflow instance. (Inherited from WorkflowInstance.)
Public methodPersistPersists a workflow instance to an instance store.
Public methodPersist(TimeSpan)Persists a workflow instance to an instance store using the specified time-out interval.
Protected methodRegisterExtensionManagerCalled by the host to register the specified extension manager, validate that all required extensions are present, and to initialize the collection of extensions to be used. (Inherited from WorkflowInstance.)
Public methodResumeBookmark(Bookmark, Object)Initiates an operation to resume the specified bookmark, using the specified value. The bookmark to be resumed is previously created by an activity within the workflow instance.
Public methodResumeBookmark(String, Object)Initiates an operation to resume the bookmark with the specified name, using the specified value. The bookmark to be resumed is previously created by an activity within the workflow instance.
Public methodResumeBookmark(Bookmark, Object, TimeSpan)Initiates an operation to resume the specified bookmark, using the specified value and time-out interval. The bookmark to be resumed is previously created by an activity within the workflow instance.
Public methodResumeBookmark(String, Object, TimeSpan)Initiates an operation to resume the bookmark with the specified name, using the specified value and time-out interval. The bookmark to be resumed is previously created by an activity within the workflow instance.
Public methodRunBegins or resumes the execution of a workflow instance.
Public methodRun(TimeSpan)Begins or resumes the execution of a workflow instance using the specified time-out interval.
Public methodTerminate(Exception)Terminates a workflow instance using the specified exception.
Public methodTerminate(String)Terminates a workflow instance using the specified error message.
Public methodTerminate(Exception, TimeSpan)Terminates a workflow instance using the specified exception and time-out interval.
Public methodTerminate(String, TimeSpan)Terminates a workflow instance using the specified error message and time-out interval.
Protected methodThrowIfReadOnlyThrows an InvalidOperationException if the workflow instance has been initialized, as determined by IsReadOnly. (Inherited from WorkflowInstance.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodUnloadPersists and unloads a workflow instance.
Public methodUnload(TimeSpan)Persists and unloads a workflow instance using the specified time-out interval.
Top

The WorkflowApplication class provides a host for a single workflow instance. It is a thread-safe proxy to the actual workflow instance that is managed by the workflow runtime. Users of WorkflowApplication can instruct the workflow runtime to perform actions on a workflow instance by calling the appropriate methods on a WorkflowApplication object. If a requested action is not valid, an exception is thrown.

Using WorkflowApplication you can perform the following tasks:

  1. Create a new workflow instance, or load a workflow instance from an instance store.

  2. Provide extensions to be used by activities within a workflow instance.

  3. Control the execution of a workflow instance.

  4. Resume a bookmark created by an activity within a workflow instance.

  5. Persist or unload a workflow instance.

  6. Be notified of workflow instance lifecycle events.

The following example hosts a workflow using WorkflowApplication. A WorkflowApplication instance is constructed using the specified workflow definition, the desired workflow lifecycle events are handled, and the workflow is invoked with a call to Run. When the workflow is completed, the following output is displayed to the console.

Starting the workflow. Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Idle. Ending the workflow. Workflow 593976e8-558d-4989-94d6-50a14b34fd7b CompletedWorkflow 593976e8-558d-4989-94d6-50a14b34fd7b Unloaded. 

Activity wf = new Sequence
{
    Activities =
     {
         new WriteLine
         {
             Text = "Starting the workflow."
         },
         new Delay
         {
             Duration = TimeSpan.FromSeconds(5)
         },
         new WriteLine
         {
             Text = "Ending the workflow."
         }
     }
};

// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(wf);

// Subscribe to any desired workflow lifecycle events.
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    if (e.CompletionState == ActivityInstanceState.Faulted)
    {
        Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
        Console.WriteLine("Exception: {0}\n{1}",
            e.TerminationException.GetType().FullName,
            e.TerminationException.Message);
    }
    else if (e.CompletionState == ActivityInstanceState.Canceled)
    {
        Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
    }
    else
    {
        Console.WriteLine("Workflow {0} Completed.", e.InstanceId);

        // Outputs can be retrieved from the Outputs dictionary,
        // keyed by argument name.
        // Console.WriteLine("The winner is {0}.", e.Outputs["Winner"]);
    }
};

wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
    // Display the exception that caused the workflow
    // to abort.
    Console.WriteLine("Workflow {0} Aborted.", e.InstanceId);
    Console.WriteLine("Exception: {0}\n{1}",
        e.Reason.GetType().FullName,
        e.Reason.Message);
};

wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
    // Perform any processing that should occur
    // when a workflow goes idle. If the workflow can persist,
    // both Idle and PersistableIdle are called in that order.
    Console.WriteLine("Workflow {0} Idle.", e.InstanceId);
};

wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
    // Instruct the runtime to persist and unload the workflow
    return PersistableIdleAction.Unload;
};

wfApp.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
    Console.WriteLine("Workflow {0} Unloaded.", e.InstanceId);
};

wfApp.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
    // Display the unhandled exception.
    Console.WriteLine("OnUnhandledException in Workflow {0}\n{1}",
        e.InstanceId, e.UnhandledException.Message);

    Console.WriteLine("ExceptionSource: {0} - {1}",
        e.ExceptionSource.DisplayName, e.ExceptionSourceInstanceId);

    // Instruct the runtime to terminate the workflow.
    // Other choices are Abort and Cancel
    return UnhandledExceptionAction.Terminate;
};

// Run the workflow.
wfApp.Run();


.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

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.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.