Class WorkflowHost
Provides a host for a single instance of a workflow. Hosts provide access to the workflow data context and the ability to raise workflow events.
public sealed class WorkflowHost : IDisposable
- Inheritance
-
WorkflowHost
- Implements
- Inherited Members
Constructors
WorkflowHost(IActivity, IParameterValueProvider, IServiceProvider)
Creates a workflow host for the specified activity and starts the workflow.
public WorkflowHost(IActivity activity, IParameterValueProvider parameterValueProvider, IServiceProvider serviceProvider)
Parameters
activity
IActivityThe root workflow activity.
parameterValueProvider
IParameterValueProviderThe parameter value provider for the workflow to use.
serviceProvider
IServiceProviderThe service provider for the workflow to use.
Remarks
If the workflow execution throws an exception synchronously, the workflow host will still be created, and the exception will be exposed via a faulted Task.
Exceptions
- ArgumentNullException
activity
is null.- ArgumentNullException
parameterValueProvider
is null.- ArgumentNullException
serviceProvider
is null.
WorkflowHost(IActivity, IServiceProvider)
Creates a workflow host for the specified activity and starts the workflow.
public WorkflowHost(IActivity activity, IServiceProvider serviceProvider)
Parameters
activity
IActivityThe root workflow activity.
serviceProvider
IServiceProviderThe service provider for the workflow to use.
Remarks
If the workflow execution throws an exception synchronously, the workflow host will still be created, and the exception will be exposed via a faulted Task.
Exceptions
- ArgumentNullException
activity
is null.- ArgumentNullException
serviceProvider
is null.
Properties
DataContext
Gets the workflow data context, which provides access to the workflow-level variables (i.e., variables defined by the top-level activity).
public WorkflowDataContext DataContext { get; }
Property Value
Remarks
This supports full binding functionality from WPF views.
Result
Gets the result of the workflow if the root activity produces a result, or null if it does not or if the workflow has not completed execution.
public object Result { get; }
Property Value
Task
Gets the Task representing the workflow execution.
public Task Task { get; }
Property Value
Remarks
If the workflow execution fails, the task will result in a faulted state with one of the following exceptions:
- WorkflowParameterException: An error occurred initializing parameter values within the workflow.
- WorkflowException: An unhandled error occurred in the workflow. InnerException will contain the unhandled exception.
Methods
Dispose()
Closes and releases all resources used by the WorkflowHost. If the workflow is running, this will request cancellation first, closing and releasing all resources once the workflow completes.
public void Dispose()
RaiseEvent<TEvent>(TEvent)
Raises an event on the workflow event bus.
public void RaiseEvent<TEvent>(TEvent e)
Parameters
e
TEventThe event.
Type Parameters
TEvent
The event type.
Remarks
See the remarks for RaiseEvent<TEvent>(TEvent) for more information.
Exceptions
- ObjectDisposedException
The object has been disposed.
RequestCancel()
Requests canceling the workflow execution.
public void RequestCancel()
Exceptions
- ObjectDisposedException
The object has been disposed.