Listen Activity in state machine workflows

Hi,

Can we use listen activity in state machine workflows.

Here is my case, where i need to use listen activity, (which i thouht it would be better)

I have created state machine workflow for my web application and when web app raises some events, i have to change the state of my workflow from one state to another.

In the workflow, I have an event, which executes sequence of 7 steps. When user clicks a button in my aspx page, i am raising the event and the event performs all these 7 steps. Its working fine!

Now i got another requirement, that user can raise one more event (from other button, but the state remains the same), which is very similar to that of former, but it has one different step at #2 position of sequence. The rest of the sequence remains same for both these events.

To implement this, i thought of using Listen activity with in the state activity, which listens occurance of either of events and based on the events raised, it executes 2 different paths for 2nd step and follows same sequence from 3rd step onwards and after reaching final step, changes the state to next state available.

Is there any other way to implement this scenario, or do i need to use 2 event driven activities by duplicating all the 7 sequntial steps

Thanks in advance

Pavan




Answer this question

Listen Activity in state machine workflows

  • senthil_palraj_e81a78

    Pavan,

    You cannot use other event driven activities in the state machine workflow. If you have two different events then you need two different event driven activities in the state.

    Other options:

    1) Use the same event, but have your event arguments include the flag to indicate whether the particular activity should execute. You CAN use an If/Else activity in the event driven activity.

    2) Create a composite activity that simply wraps up the current activities you are using in your eventdriven (including the optional one). Expose a property on the composite which allows you to set a flag to indicate if you should execute that activity. Then, in the state, have the two events contain your composite activity. Set the flag accordingly to execute the optional activities.

    Option 2 allows you to maintain the code/activities in one place but still model two different events on the workflow.

    Matt



  • Harpreet Singh

    Hi Matt,

    I found a solution to my problem (not sure whether it is elegent though) finally.

    I have split my state machine, which is now one in shape into 2 state activities, one which holds the events and second state activity holds the post event handling activities (common for all events) and encapsulated them in single state activity.

    After an event is raised, the state, that holds event activities gets executed and passes the state to post event handlers.

    After post event hander finishes its execution, it resets the state back to event handler state.

    This way, atleast, i got assured that, post event handlers are common for all the events.

    Thanks a lot for your support.

    Regards,

    Pavan


  • PhilippCH

    Hi Matt,

    Thanks a lot for the reply.

    I have tried to implement option #1, but it is not allowing me to insert IfElese activity as first child for event driven activity.

    The exception i got was:

    "The EventDrivenActivity child should implement System.Workflow.Activity.IEventActivity' and i am getting compilation errors.

    And the 2nd option is more elegant, and i have yet to try it. But my only concern is the extensibility, as let us say, if i want to add one more event driven activity (similar to the rest of the group), then i need to add all the optional child activities in the composite activity, that are directly related to the new event driven activitiy.

    Hope you can assess the situation.

    Regards,
    Pavan


  • Listen Activity in state machine workflows