Events exposed through Activity class

Hi,

I was wondering if it's possible to wire up with event exposed on Activity class (more specifically EventDriveActivity class) obtained through tracking instance on a host

</snippet> Code in a Runtime Host

Activity currentActivity = memoryTrackingInstance.CurrentState.GetActivityByName("ActionName", true);

if (currentActivity is EventDrivenActivity)

{

EventDrivenActivity evtActivity = (EventDrivenActivity)currentActivity;

evtActivity.Closed += delegate(object sender, ActivityExecutionStatusChangedEventArgs args)

{

// do something

};

}

</snippet>

Problem is the body of a delegate never gets called. I understand the communication between the host and the workflow instance is done via dataExchangeService still I was hoping you are able to bind the delegate into runtime instance somehow.

Problem is the host is loading all the workflows and their corresponding dataService libraries dynamicaly and knows nothing about them except a small xml definition describing what to load and from where. All the info it needs is obtained via reflection (to fire events from dataService libraries).

This is exactly where the problem lies. After firing an event into a workflow, calling method needs to block execution and wait till (preferably event from EventDrivenActivity - evtActivity.Closed - would happen).

There is also a method exposed on Activity class - RegisterForStatusChanged(...) however I've no clue as how to use it.

I'd prefer solution that don't involve enforcing rules and implementing additional code (CallExternalMethod) into the workflow itself just to be able to message something back to the Host.

thanks in advance,

Zoran Bebic



Answer this question

Events exposed through Activity class

  • hepower

    Thanks Angel, I kinda knew this is how it's going to be in the end but was hoping I was wrong and thus made this post :)

    And yeah I agree, wapping this functionality into a custom activity sounds ok.


  • Aelphaeis_Mangarae

    Zoran,

    Activity status change events are meant only for parent-child protocol - for example a Sequence listening for one of its children to finish executing so that it can schedule the next one. These events are only raised for subscribing activities that are executing (i.e. not 'Initialized' or 'Closed'), otherwise the subscriber is ignored and this is why your event handler is not being called.

    What you are essentially trying to do is synchronize two thread - the host thread and the workflow thread, at the point that the message has been received by the EventSinkActivity. In order to achieve this, you need some form of callback from the workflow.

    Although there are a few ways to acheive this, the easiest reliable solution is to have a CallExternalMethodActivity call back into the service. I understand that you don't want to have additional logic in your workflow for this, but you can easily abstract this through custom activities. You can create a custom activity that contains the receive-callback pair inside of it, and looks like a regular receive when used in the workflow.



  • Events exposed through Activity class