Re: Killig orphaned processes

  •  05-14-2008, 7:39

    Re: Killig orphaned processes

    There are several ways to do this, but here is the approach I generally use.

    In the sub process, I have two parallel paths from the start.  One path is the normal workflow.  The other path leads to an activity that contains a SmartObject Event and two Server Code Events.  The SmartObject event writes the serial number and a key identifier to a SmartObject.  The key identifier is something that uniquely identifies this sub process as belonging to the main process.  Next it goes to the first code event, which contains a single line to set the event to asynchronous.  Setting the event to asynchronous will cause it to wait until the event is completed.  The second code event (or the Goto Activity Event found on blackmarket) simply goes to the next activity on this path.  Draw a line from the first activity to the second activity on this path even though you will be using a Goto.  The second activity on this path uses another SmartObject event to delete the entry that was written by the first SmartObject event.  This removes the information about this process from the table.

    On the main path of the sub process, before it ends I also use a SmartObject event that removes information about this process from the table.  You will also need to use a Goto on this path.  I don’t recommend using a Goto for branching logic.  The reason we are using it here is Goto has the side-effect of cancelling parallel paths.  In this case, the one path will hit the async server event and wait forever until the event is completed.  If the normal path completes, this path will be cancelled by the Goto and the entry will be removed from the table.

    So how do you cancel this process if the calling process is finished?  In the main workflow, before you end, put in a SmartObject event that does a List of all the sub-process serial numbers in the table that match your key information.  I modify the SmartObject event with a little custom code.  For each sub-process, this custom code takes the serial number of the async event in the child process and uses the API to invoke the Finish method on it.  This causes the async server event in the sub-process to complete and the process exits down the path that removes the entry from the table and does a Goto to cancel parallel paths.

    Here’s a tip:  I put the code that uses the API to Finish the server event in an assembly in the GAC.  If you’re interested, I can post this code.

    You can also search the forums because this question has been asked before and there are multiple techniques.


    The statements and opinions made in my postings are my own, and do not reflect the opinions of SourceCode Technology Holdings, Inc. or its subsidiaries. All information is provided as is with no warranties, express or implied, and grants no rights or licenses.
    Filed under: ,
View Complete Thread