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
activityIActivityThe root workflow activity.
parameterValueProviderIParameterValueProviderThe parameter value provider for the workflow to use.
serviceProviderIServiceProviderThe 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
activityis null.- ArgumentNullException
parameterValueProvideris null.- ArgumentNullException
serviceProvideris null.
WorkflowHost(IActivity, IServiceProvider)
Creates a workflow host for the specified activity and starts the workflow.
public WorkflowHost(IActivity activity, IServiceProvider serviceProvider)
Parameters
activityIActivityThe root workflow activity.
serviceProviderIServiceProviderThe 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
activityis null.- ArgumentNullException
serviceProvideris 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
eTEventThe event.
Type Parameters
TEventThe 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.