tags:

views:

51

answers:

3

Hi,

while working with WF 4.0 I noticed that the WorkflowApplication class exposes action properties (Aborted, Complete, etc...) instead of events. Is there a specific reason? When should I prefer action properties instead of events?

Thank you

+3  A: 

Wow; I see what you mean; that really surprises me.

However, if you can't think of a good reason to use properties here (and I can't), then stick to events; they avoid a range of problems (accidental unsubscription and inappropriate invocation being the biggest).

The only thing I can think of is that maybe they needed this for serialization purposes, but I can think of other ways to crack that nut. Alternatively, maybe regular events don't make sense in the crazy "dependency property" / "attached property" / "routed event" world of WF.

Marc Gravell
Thank you...I'm wondering if it's just because they're easily serializable through Xaml..or maybe they can be more easily handled by the designer...
fra
@fra - re the latter, the winforms designer has managed with regular events for years... presumably they would have just lifted some code from there?
Marc Gravell
+1  A: 

Edit: the following isn't accurate, see Marc's comment below.

For one thing, events allow multiple handlers inherently while an Action property only allows a single handler. Yes, the Action property could do a broadcast itself, but that isn't very cohesive or idiomatic.

I'm with Marc on this one, I'm surprised they used Action properties instead of standard events.

Chris Schmich
Well, *if you use* += / -=, a delegate property will behave (at the superficial level) *identically* to the event. So a bit hard to argue that it only allows a single handler.
Marc Gravell
@Marc: good point, and that's even more reason to stick to events since one user might use `+=` while another just does `=` which would effectively remove the first.
Chris Schmich
A: 

I sent an email to one member of the WF team and, kindly, he answered me. He told me that events and actions are almost equivalent, but the team had better feeling with the API using actions.

fra