Problem creating multiple dynamic destinations

  • 14 November 2006
  • 14 replies
  • 3 views

Badge +3
I have a Master and Child workflow. The Master workflow has 3 Activities. On one of the Activities I make an IPC call to the Child workflow. The destination rule of this activity assigns "n" amount of users to it, and therefore creates "n" amount of Child workflows.


.Value);

bool bAllTrue = true;
CDest1 oDest1 = new CDest1();
oDest1.Main(ref K2);
for (int i=0;i<backgroundChecks;i++)
{
if (oDest1.IsSuccess == true) {
//== sendto

string user = "BackgroundCheck"+i;
K2.Destinations.Add(DestinationType.User,user);

if (bAllTrue == false)
{
return;
}
}

}

}

// Destination Classes

private class CDest1 {
public bool IsSuccess = false;

public void Main(ref DestinationRuleContext K2) {
this.IsSuccess = true;
}

}


That is the code behind my destination rule where the Datafield "childCount" is a variable integer that I set prior to this activity. Depending on what that number is, I want to be able to create that many Child workflows.

It all seems to work well except for 1 instance goes into error. Everytime.


Debug 5010 Executing Code Item IPCEvent - IPC Server
Debug 5170 Executed Proc:Main(218), Item:IPC Server.IPCEvent, Status:Active
Debug 5050 Executing IPC Event IPC Server(14), Act:MainFirstActivity(6), Proc:Main(218)
Debug 5010 Executing Code Item IPCEvent - IPC Server
Debug 5170 Executed Proc:Main(218), Item:IPC Server.IPCEvent, Status:Active
Debug 5050 Executing IPC Event IPC Server(15), Act:MainFirstActivity(6), Proc:Main(218)
Debug 5010 Executing Code Item IPCEvent - IPC Server
Debug 5170 Executed Proc:Main(218), Item:IPC Server.IPCEvent, Status:Active
Debug 5100 Executing Line Rule Child First Rule(3), StartAct:Start(2), Proc:Child(220)
Debug 5010 Executing Code Item LineRule - Child First Rule
Debug 5100 Executing Line Rule Child First Rule(3), StartAct:Start(2), Proc:Child(221)
Debug 5010 Executing Code Item LineRule - Child First Rule
Debug 5017 First Chance Exception in Code Item LineRule - Child First Rule : Item has already been added. Key in dictionary: '107' Key being added: '107'

Error 5015 Unhandled Exception in Code Item LineRule - Child First Rule : Item has already been added. Key in dictionary: '107' Key being added: '107'

Debug 5170 Executed Proc:Child(220), Item:Child First Rule.LineRule, Status:Error

Debug 5100 Executing Line Rule Child First Rule(3), StartAct:Start(2), Proc:Child(219)
Debug 5010 Executing Code Item LineRule - Child First Rule


This is the Error message I get when I open K2Server console. Here my Main workflow creates 3 Child workflows, IDs 219,220,221 and 219 is the one that goes into error.

On the Activity I have selected, "Create a slot for each destination" and there are no preceding or succeeding rules. There is a value for the datafield (I had this posted to the console). It also shows the n users that I create for the destination. Note: These users don't actually exist in ADUM though.

When I go to Server Manager and repair error, it goes through without a hitch.

Any glaring mistakes I am making here? Any help would be much appreciated.

14 replies

Badge +11
Can't pick up any obvious mistakes in the code...

Are you using a synchronous or asynchronous IPC event?
Is the IPC Event the last event in the parent process?
Do you pass any data- or xml fields from Parent to child?

Regards,
Ockert
Badge +3
Its a Synchronous call from the IPC event.

The IPC is the only event in the Activity but the Activity is the first Activity in the process

The only data I pass from Parent to child is the Folio. I have a DataField in the parent process called childFolio, and I assign that to the Child Folio. I use the GUI for all the IPC interaction.

I am using version 3.6262.1.0 SP4 on a Windows 2003 Server OS.

Other than the destination rule the flow is so simple. The only thing I can think of that it is trying to do is that it is trying to Create two things at the same time rather than one after the other and therefore using the same ID or Key. What is it trying to say when it spits out the error:


Error 5015 Unhandled Exception in Code Item LineRule - Child First Rule : Item has already been added. Key in dictionary: '107' Key being added: '107'


What is it adding and where? I don't have anything behind any of my line rules as yet. They all just have a blank as there is no logic required.
Badge +3
Not sure what has happened but I have changed part of my code where I do the loop in the the destination rule to make i start from 1 rather than 0.


for (int i=1;i<=backgroundChecks;i++)


It now can work SOME of the time. I had run over 30 tests with the other code and it fell over every time.
I have now run the test close to the same amount of time and it manages to work slightly less than half the time. Could it be the Folio/childFolio interaction?
I can't see why starting from 0 or 1 would make a difference in this case, other than the fact that i gets concatinated with the user and added to the Destination.

I've run out of ideas myself. The tests I am running are just inconsistent. Would posting the flow help?
Badge +11
As a test, try to start your Parent process synchronously i.e. use something like:
oK2Connection.StartProcessInstance(oNewProcessInstance, true);

Regards,
Ockert
Badge +3
That seems to do the trick I think. :)

Thanks for the help. Not sure I understand fully what was happening though?

But again, it works now so thank you.
Badge +3
This issue has returned.
Changes:
The Activity which calls the IPC Event is now the second Activity in the chain.
The IPC Event has been modified in the code behind to change a few more settings and modify DataField values.

It seems as though it is trying to make 2 IPC calls at the same time or with the same Id number...

Being as it is now the second Activity in the chain, should I need to set something in the previous Activity or inside the code behind?

I have also posted an issue with regard to this same Event, i am sort of working on 2 versions of the same workflow and getting no where with each... any help will be much appreciated.
Badge +3
Seems that if inside the Code Window, if I set the K2.Synchronous to be false I get the Error message.
If I set the K2.Synchronous to be true, it works fine.

My problem is that I wish to create Multiple Child Processes and have it so that all the Child Processes complete First, before moving on from that Activity.

Can I have my cake and eat it too? It's 11.39pm in Perth Australia, and I have been working since 8am this morning... I truly desparately need a solution to this problem, if not a solution, then a better understanding of what is actually happening here. What key in what dictionary is it trying to add to?

Can I set the K2.Synchronous to true, but still have it wait for the complete somehow?

Is there a way to delay the transaction for when it executes the IPC events, after it has entered the Activity. In a previous solution I had this problem, I had an Activity that looped over itself multiple times, and it created this error. I delayed the start time to be 3 seconds apart and it resolved it. However, that is set before you enter the Activity. Is there a way to do this inside the IPC Event itself.
Badge +3
Seems that you have to set K2.Synchronous = true inside the IPC event. To then make the Parent Process Activity wait for all the Child Processes to complete, you need to set Succeeding Rule which loops through all the destination queues and compares the ActInstDest.Status to "Complete". If all the destination queues are completed it will execute Succeeding Rule and move on.

Means a lot of looping processes each time a Child Process completes, but seems as though it is the only way.
Badge +5
I was having the exact same problem. To avoid the problem I do a system.Threading.Thread.Sleep(2000) in the IPC event.

Not a nice solution, but it does the trick for me.
Badge +11
Please contact your local support office for a fix for this issue.
Sleeping threads is not a good idea - causing K2.net server to run out of threads and will ultimately crash due to - not enough memory. Depending on the number of processes you start of course.

HTH,
Ockert
Badge +5
Before I'm contacting my local support office (I'm behind schedule and would like a quick fix)

Isn't it possible in an other way to let my code wait a few seconds ? (without using thread.sleep) could a timer help ?
Badge +11
Not that I know of but if Thread.Sleep works for you as a temporary workaround that's fine - as long as you get the fix from support before deploying to production. Just be aware that there is a possibility of running out of threads and memory which MAY cause the server to crash.

Regards,
Ockert
Badge +3

Hello There,


How will the child instances of the workflow behave?


Do They run in parallel or serial.


 


Regards


Amarnath

Badge +2

The following blog post by k2eric should answer all these questions:


http://www.k2underground.com/blogs/blackpointtipsandtricks/archive/2009/05/28/inter-process-communication-ipc-event.aspx


HTH

Reply