Freigeben über


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>.

CustomInvokeWorkflowActivity.exe

Comments

  • Anonymous
    July 14, 2006
    PingBack from http://microsoft.wagalulu.com/2006/07/14/do-you-want-to-invoke-another-workflow-but-you-wont-know-which-one-until-runtime/

  • Anonymous
    August 16, 2006
    Thanks for this sample.This is what I was exactly looking for

  • Anonymous
    October 08, 2006
    En estos dias, he ordenado algunos enlaces y recursos sobre el Windows Workflow Foundation, el motor

  • Anonymous
    March 12, 2007
    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

  • Anonymous
    May 31, 2007
    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

  • Anonymous
    July 26, 2007
    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>()

  • Anonymous
    September 24, 2008
    The comment has been removed