Skip to main content

I encountered some problems when I have to stop WF instances from a WF.
My case was look like this:
WF 1 calls WF 2a, 2b, 2c.
WF 2a calls WF 3a
WF 2b call WF 3b.
In WF 3b I have a activity to stop all WF except itself.
All of them has Folio starting with "ABC". All of sub WF are called synchronous. WF 1 have 3 branches, each branch call 1 WF.

My method is using:
SourceCode.Workflow.Management.ProcessInstances pIs = wms.GetProcessInstancesAll("%", "%", "%");
foreach (SourceCode.Workflow.Management.ProcessInstance pI in pIs)
{
if ((pI.ID != processID) && (pI.Folio.StartsWith(PTRFNumber)))
{
if ((pI.Status == "1")
|| (pI.Status == "2"))
{
SourceCode.Workflow.Management.ProcessInstances lstCheck = wms.GetProcessInstances(pI.ProcID, pI.Folio);
if (lstCheck.Count != 0)
{
WriteLog(DateTime.Now.ToString(), "Service DeleteStopStartWFInstances: Stop WF instances: " + pI.Folio);
wms.StopProcessInstances(pI.ID);
}
}
}
}

Problems start here:
1. After checking database and testing, I found out that when I call WF 1, it start and go to 3 branches at the same time. But WF 2a,2b,2c don’t start like this.
WF 2a start first, then 3a. After that 2b and 3b. And last is 2c. It has delay time between starting those WFs
The problem here is user can call 3b independent. Therefore, when I call WF 3b, first it search all WF are running. At that time, I only have WF 1,2a,2b in database.
Therefore I miss 2b,3b,2c in list WFs I need to stop.
2. It seems that when calling WF 3b at the time WF1 running and starting other WFs, K2 has to wait for all sub WFs start. Only after that, it do my command to stop WF instances.
=> So when my first commands done, it count all of WF instances are running. But when go to step 2 to stop, although command to stop runs immediatetly, its has to wait for a period of time.
But after that, some instances may complete. Then I get exception: Process instance not found.
3. At first I cannot stop WF if call WF 3b like above. Because all sub WFs are called synchronous( including WF 3b), when i do that, WF 3 remain in activity that stop all Wfs forever with status Running.
After that, I have a solution to use Webservice. But if calls webservice sync, it’s still the same. I hace to use async. But it’s hard to control whether I can call webservice or not.

Be the first to reply!

Reply