WorkflowRuntime::CreateWorkflow Method (XmlReader^)

 

Creates a workflow instance by using the specified XmlReader.

Namespace:   System.Workflow.Runtime
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)

public:
WorkflowInstance^ CreateWorkflow(
	XmlReader^ workflowDefinitionReader
)

Parameters

workflowDefinitionReader
Type: System.Xml::XmlReader^

An XmlReader that contains the workflow definition.

Return Value

Type: System.Workflow.Runtime::WorkflowInstance^

The created workflow instance.

Exception Condition
ArgumentNullException

workflowDefinitionReader is a null reference (Nothing in Visual Basic).

ObjectDisposedException

The WorkflowRuntime is disposed.

The workflow instance is created from a XAML workflow definition file referenced by the XmlReader.

Before the WorkflowInstance is created, validation is executed on it. If any validation errors occur, the WorkflowValidationFailedException is thrown. This works well for simple scenarios, but in a server environment, revalidating a workflow for every activation might be unnecessary overhead.

For more information about disabling validation, see ValidateOnCreate.

The following example demonstrates how to create a workflow given a XAML-based workflow definition.

static void Main(string[] args)
{
    using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
    {
        AutoResetEvent waitHandle = new AutoResetEvent(false);
        workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
        {
            waitHandle.Set();
        };
        workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
        {
            Console.WriteLine(e.Exception.Message);
            waitHandle.Set();
        };

        TypeProvider typeProvider = new TypeProvider(null);
        // Add referenced assemblies, if needed
        // typeProvider.AddAssembly(...);
        workflowRuntime.AddService(typeProvider);

        using (XmlReader reader = XmlReader.Create("Workflow1.xoml"))
        {
            WorkflowInstance instance = workflowRuntime.CreateWorkflow(reader);
            instance.Start();
        }

        waitHandle.WaitOne();
    }
}

.NET Framework
Available since 3.0
Return to top
Show: