chakravarthy_b

Hi,

I have a workflow names 'FirstWorkflow' with following activities in the following order:

1)codeactivity1

2)invokeworkflow -> targetworkflow is 'SecondWorkflow'

3)codeactivity2

SecondWorkflow is like this

1)codeactivity3

2)codeactivity4

Now when I run the 'FirstWorkflow' like

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(FirstWorkflow));

output is like this:

codeactivity1

codeactivity2

codeactivity3

codeactivity4

But I want o/p like this:

codeactivity1

codeactivity3

codeactivity4

codeactivity2

That means my FirstWorkflow should wait until SecondWorkflow completes.

Suggest me some good ideas

Regards,

Chakri.



Re: Windows Workflow Foundation regarding invokeworkflow

Shelly Guo - MSFT

Unfortunately what you want is not easy. Today the InvokeWorkflow works as "fire-and-forget". It starts the second workflow and returns immediately. There is no built-in mechanism for the first workflow to know when the second workflow finishes.

One suggestion I can think of is to add an event activity in the first workflow after the InvokeWorkflow and then signal the event activity at the end of the second workflow.

Shelly Guo





Re: Windows Workflow Foundation regarding invokeworkflow

ElifOn - MSFT

Hi

Another thing you can do to have a synced invoke workflow is to play with the runtime a bit.

In the Main method, add a delegate to WorkflowStarted and if you hit the worklfow started the second time (just have a flag that would count how many times workflowstarted is called and the second time would mean that the invoked workflow has just started) unload the outer workflow instance. After that when the workflow completed delegate is called the first time - which means the invoked workflow has completed- reload back the outer workflow instance and you will be able to have the

Code 1,

Code 3

Code 4

Code 2 output.

Let me know if you have any difficulty.

Thanks

Elif






Re: Windows Workflow Foundation regarding invokeworkflow

chakravarthy_b

Hi,

Some change in my problem like this

I have a workflow names 'FirstWorkflow' with following activities in the following order:

1)codeactivity1

2)invokeworkflow -> targetworkflow is 'SecondWorkflow'

3)codeactivity2

4)codeactivity3

SecondWorkflow is like this

1)codeactivity4

Now when I run the 'FirstWorkflow' like

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(FirstWorkflow));

output is like this:

codeactivity1

codeactivity2

codeactivity3

codeactivity4

But I want o/p like this:

codeactivity1

codeactivity2

codeactivity4

codeactivity3

That means codeactivity3 in FirstWorkflow should wait until SecondWorkflow completes.

Suggest me some good ideas

Regards,

Chakri.





Re: Windows Workflow Foundation regarding invokeworkflow

ElifOn - MSFT

I believe my previous answer was not explanatory enough so i will try to express how this could be done with a workaround the following way:

In your main method after you create your instance:

workflowruntime.WorkflowStarted += delegate

{

//here you need a flag to check if this is the first time or the second time you are entering the workflow started

if second time -> then

Unload(instance) //this unloads the outer workflow

}

worklfowruntime.WorkflowCompleted += delegate

{

//here you need to check if workflow completed has been hit once, which will be the first time the second workflow completes

if first time-> then

Load(instance) // this reloads the outer workflow and it will keep on running from where it stopped meaning right after the invokeWorkflow is hit

}

You need to have a persistence service to unload and load the outer workflow.

Please let me know if this works

Thanks

Elif






Re: Windows Workflow Foundation regarding invokeworkflow

chakravarthy_b

i am new to WF.

can u tell me how to load and unload instances.





Re: Windows Workflow Foundation regarding invokeworkflow

ElifOn - MSFT

instance.Unload()

instance.Load()

Let me know once you try it out

Thanks

Elif