Welcome to MSDN Blogs Sign in | Join | Help

Do you want to invoke another workflow but you won't know which one until runtime?

The InvokeWorkflowActivity that ships with WF requires you to set the type of the target workflow at design time.  If you won’t know which workflow to invoke until runtime you need to write a custom activity. To invoke a workflow need to use the IStartWorkflow service that you can get from the ActivityExecutionContext, like the following:

 

IStartWorkflow startWorkflow = executionContext.GetService(typeof(IStartWorkflow)) as IStartWorkflow;

 

Guid instanceId = startWorkflow.StartWorkflow(this.TargetWorkflow, this.Parameters);

 

Since the parameters won’t be known until runtime you can’t use the WorkflowParameterBindingsCollection because you wouldn’t be able to change in at runtime.  Instead I have have a parameters property that is type Dictionary<string, object>.

Published Friday, July 14, 2006 4:45 PM by tomlake
Attachment(s): CustomInvokeWorkflowActivity.exe

Comments

# Do you want to invoke another workflow but you won&#8217;t know which one until runtime? &raquo; Wagalulu - Microsoft &raquo; &raquo; Do you want to invoke another workflow but you won&#8217;t know which one until runtime?

Wednesday, August 16, 2006 11:04 AM by keshavbs

# re: Do you want to invoke another workflow but you won't know which one until runtime?

Thanks for this sample.This is what I was exactly looking for
Monday, October 09, 2006 5:50 AM by Angel "Java" Lopez

# Aprendiendo Windows Workflow Foundation

En estos dias, he ordenado algunos enlaces y recursos sobre el Windows Workflow Foundation, el motor

Tuesday, March 13, 2007 7:31 AM by lodjikz

# invoking method to start statemachine workflow

Hi, thanks for this good sample.

with this

startWorkflow.StartWorkflow(this.TargetWorkflow, this.Parameters);

we can start the workflow correctly.

but how can we specify the method to be called to actually run the subworkflow, as in the invokeWorkflowActivity?

Thanks

Thursday, May 31, 2007 8:56 AM by SilverEarth

# re: Do you want to invoke another workflow but you won't know which one until runtime?

Hi,

Being new to wf,

How would one go about setting up the basic InvokeWorkflowActivity from scratch using the designer?

Can someone point me to a sample of how to do this please!

Many thanks

Thursday, July 26, 2007 9:46 AM by JB30

# re: Do you want to invoke another workflow but you won't know which one until runtime?

Help......

I am using the ManualWorkflowSchedulerService to run my workflows

How would the code changes?

I tried to get the scheduler below but it returns null.

scheduler = executionContext.GetService<ManualWorkflowSchedulerService>()

Wednesday, September 24, 2008 1:18 PM by Zhou Yu

# Localservice alternative?

Hi Tom,

Is it possible to also do this by using CallExternalMethod to invoke a local service method such as below?

public void InvokeChildJobAsync(Type workflowType, Guid instanceId)

{

   ThreadPool.QueueUserWorkItem(delegate(Object state)

   {

WorkflowInstance instance = WorkflowRuntime.CreateWorkflow(workflowType, null, instanceId);

instance.Start();

this.SubmitJob(instanceId);

   });

}

The reason I am trying to do it this way is because of the line this.SubmitJob(instanceId), where I need to raise an event to the invoked workflow in addition to starting it.  Please let me know if this is feasible or if you see any issues.

Thanks,

-Zhou

Anonymous comments are disabled
 
Page view tracker