Upravit

Sdílet prostřednictvím


WorkflowRuntime.CreateWorkflow Method

Definition

Creates a workflow instance by using the specified parameters.

Overloads

CreateWorkflow(XmlReader, XmlReader, Dictionary<String,Object>, Guid)

Creates a workflow instance by using the specified parameters.

CreateWorkflow(Type, Dictionary<String,Object>, Guid)

Creates a workflow instance by using the specified parameters.

CreateWorkflow(XmlReader, XmlReader, Dictionary<String,Object>)

Creates a workflow instance by using the specified XmlReader objects and the arguments contained in the specified Dictionary<TKey,TValue>.

CreateWorkflow(XmlReader)

Creates a workflow instance by using the specified XmlReader.

CreateWorkflow(Type)

Creates a new workflow instance by using the specified workflow Type.

CreateWorkflow(Type, Dictionary<String,Object>)

Creates a workflow instance by using the specified workflow Type and the arguments to the workflow contained in the specified Dictionary<TKey,TValue>.

Remarks

If the workflow run-time engine has not been started, the CreateWorkflow methods call StartRuntime. See StartRuntime for a list of possible exceptions. After you create the workflow instance, call WorkflowInstance.Start on the WorkflowInstance object returned by the CreateWorkflow method to begin its execution.

CreateWorkflow(XmlReader, XmlReader, Dictionary<String,Object>, Guid)

Creates a workflow instance by using the specified parameters.

public:
 System::Workflow::Runtime::WorkflowInstance ^ CreateWorkflow(System::Xml::XmlReader ^ workflowDefinitionReader, System::Xml::XmlReader ^ rulesReader, System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ namedArgumentValues, Guid instanceId);
public System.Workflow.Runtime.WorkflowInstance CreateWorkflow (System.Xml.XmlReader workflowDefinitionReader, System.Xml.XmlReader rulesReader, System.Collections.Generic.Dictionary<string,object> namedArgumentValues, Guid instanceId);
member this.CreateWorkflow : System.Xml.XmlReader * System.Xml.XmlReader * System.Collections.Generic.Dictionary<string, obj> * Guid -> System.Workflow.Runtime.WorkflowInstance
Public Function CreateWorkflow (workflowDefinitionReader As XmlReader, rulesReader As XmlReader, namedArgumentValues As Dictionary(Of String, Object), instanceId As Guid) As WorkflowInstance

Parameters

workflowDefinitionReader
XmlReader

An XmlReader that contains the workflow definition.

rulesReader
XmlReader

An XmlReader.

namedArgumentValues
Dictionary<String,Object>

A Dictionary<TKey,TValue> of objects keyed by a string that represents the arguments to the workflow.

instanceId
Guid

The Guid of the specific WorkflowInstance to create.

Returns

The created workflow instance.

Exceptions

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

Remarks

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 workflow instanceId for any running workflows loaded by the WorkflowRuntime must be unique. If you pass an instanceId to create a workflow and a running workflow is already using that instanceId, an InvalidOperationException is thrown.

For an example of passing in parameters to CreateWorkflow, see Workflow with Parameters Sample.

For an example of using rules defined in XML, see IfElse with Rules Sample.

Applies to

CreateWorkflow(Type, Dictionary<String,Object>, Guid)

Creates a workflow instance by using the specified parameters.

public:
 System::Workflow::Runtime::WorkflowInstance ^ CreateWorkflow(Type ^ workflowType, System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ namedArgumentValues, Guid instanceId);
public System.Workflow.Runtime.WorkflowInstance CreateWorkflow (Type workflowType, System.Collections.Generic.Dictionary<string,object> namedArgumentValues, Guid instanceId);
member this.CreateWorkflow : Type * System.Collections.Generic.Dictionary<string, obj> * Guid -> System.Workflow.Runtime.WorkflowInstance
Public Function CreateWorkflow (workflowType As Type, namedArgumentValues As Dictionary(Of String, Object), instanceId As Guid) As WorkflowInstance

Parameters

workflowType
Type

The Type of the workflow to create.

namedArgumentValues
Dictionary<String,Object>

A Dictionary<TKey,TValue> of objects keyed by a string that represents the arguments to the workflow.

instanceId
Guid

The Guid of the specific WorkflowInstance to create.

Returns

The created workflow instance.

Exceptions

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

Remarks

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 workflow instanceId for any running workflows loaded by the WorkflowRuntime must be unique. If you pass an instanceId to create a workflow and a running workflow is already using that instanceId, an InvalidOperationException is thrown.

For an example of passing in parameters to CreateWorkflow, see Workflow with Parameters Sample.

Applies to

CreateWorkflow(XmlReader, XmlReader, Dictionary<String,Object>)

Creates a workflow instance by using the specified XmlReader objects and the arguments contained in the specified Dictionary<TKey,TValue>.

public:
 System::Workflow::Runtime::WorkflowInstance ^ CreateWorkflow(System::Xml::XmlReader ^ workflowDefinitionReader, System::Xml::XmlReader ^ rulesReader, System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ namedArgumentValues);
public System.Workflow.Runtime.WorkflowInstance CreateWorkflow (System.Xml.XmlReader workflowDefinitionReader, System.Xml.XmlReader rulesReader, System.Collections.Generic.Dictionary<string,object> namedArgumentValues);
member this.CreateWorkflow : System.Xml.XmlReader * System.Xml.XmlReader * System.Collections.Generic.Dictionary<string, obj> -> System.Workflow.Runtime.WorkflowInstance
Public Function CreateWorkflow (workflowDefinitionReader As XmlReader, rulesReader As XmlReader, namedArgumentValues As Dictionary(Of String, Object)) As WorkflowInstance

Parameters

workflowDefinitionReader
XmlReader

An XmlReader that contains the workflow definition.

rulesReader
XmlReader

An XmlReader.

namedArgumentValues
Dictionary<String,Object>

A Dictionary<TKey,TValue> of objects keyed by a string that represents the arguments to the workflow.

Returns

The created workflow instance.

Exceptions

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

Remarks

The workflow instance is created from the workflow definition referenced by the XmlReader and the arguments supplied by namedArgumentValues.

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.

For an example of passing in parameters to CreateWorkflow, see Workflow with Parameters Sample.

For an example of using rules defined in XML, see IfElse with Rules Sample.

Applies to

CreateWorkflow(XmlReader)

Creates a workflow instance by using the specified XmlReader.

public:
 System::Workflow::Runtime::WorkflowInstance ^ CreateWorkflow(System::Xml::XmlReader ^ workflowDefinitionReader);
public System.Workflow.Runtime.WorkflowInstance CreateWorkflow (System.Xml.XmlReader workflowDefinitionReader);
member this.CreateWorkflow : System.Xml.XmlReader -> System.Workflow.Runtime.WorkflowInstance
Public Function CreateWorkflow (workflowDefinitionReader As XmlReader) As WorkflowInstance

Parameters

workflowDefinitionReader
XmlReader

An XmlReader that contains the workflow definition.

Returns

The created workflow instance.

Exceptions

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

Examples

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();  
    }  
}  

Remarks

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.

Applies to

CreateWorkflow(Type)

Creates a new workflow instance by using the specified workflow Type.

public:
 System::Workflow::Runtime::WorkflowInstance ^ CreateWorkflow(Type ^ workflowType);
public System.Workflow.Runtime.WorkflowInstance CreateWorkflow (Type workflowType);
member this.CreateWorkflow : Type -> System.Workflow.Runtime.WorkflowInstance
Public Function CreateWorkflow (workflowType As Type) As WorkflowInstance

Parameters

workflowType
Type

The Type of the workflow to create.

Returns

The created workflow instance.

Exceptions

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

Examples

The following code example demonstrates the recommended way to create a WorkflowInstance object in a workflow host using the CreateWorkflow method.

This code example is part of the Canceling a Workflow sample.

Type type = typeof(SampleWorkflow1);
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
workflowInstance.Start();
Dim workflowInstance As WorkflowInstance
workflowInstance = workflowRuntime.CreateWorkflow(GetType(SampleWorkflow))
workflowInstance.Start()

Remarks

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.

Applies to

CreateWorkflow(Type, Dictionary<String,Object>)

Creates a workflow instance by using the specified workflow Type and the arguments to the workflow contained in the specified Dictionary<TKey,TValue>.

public:
 System::Workflow::Runtime::WorkflowInstance ^ CreateWorkflow(Type ^ workflowType, System::Collections::Generic::Dictionary<System::String ^, System::Object ^> ^ namedArgumentValues);
public System.Workflow.Runtime.WorkflowInstance CreateWorkflow (Type workflowType, System.Collections.Generic.Dictionary<string,object> namedArgumentValues);
member this.CreateWorkflow : Type * System.Collections.Generic.Dictionary<string, obj> -> System.Workflow.Runtime.WorkflowInstance
Public Function CreateWorkflow (workflowType As Type, namedArgumentValues As Dictionary(Of String, Object)) As WorkflowInstance

Parameters

workflowType
Type

The Type of the workflow to create.

namedArgumentValues
Dictionary<String,Object>

A Dictionary<TKey,TValue> of objects keyed by string that represents the arguments to the workflow.

Returns

The created workflow instance.

Exceptions

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

Remarks

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.

For an example of passing in parameters to CreateWorkflow, see Workflow with Parameters Sample.

Applies to