我应该公开操作而不是事件吗?
在使用 WF 4.0 时,我注意到 WorkflowApplication 类公开操作属性(Aborted、Complete 等)而不是事件。 有具体原因吗?我什么时候应该更喜欢操作属性而不是事件?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
哇;我明白您的意思;这真的让我很惊讶。
但是,如果您想不出在这里使用属性的充分理由(我也不能),那么请坚持使用
event
;它们避免了一系列问题(最大的问题是意外取消订阅和不当调用)。我唯一能想到的是,也许他们需要这个来实现序列化目的,但我可以想出其他方法来解决这个问题。或者,也许常规事件在 WF 的疯狂“依赖属性”/“附加属性”/“路由事件”世界中没有意义。
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
event
s; 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.
编辑:以下内容不准确,请参阅下面是马克的评论。
一方面,事件本质上允许多个处理程序,而
Action
属性仅允许单个处理程序。是的,Action
属性本身可以进行广播,但这不是很有凝聚力或惯用的。我和 Marc 一起讨论这个问题,我很惊讶他们使用
Action
属性而不是标准事件。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, theAction
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.我给 WF 团队的一名成员发送了一封电子邮件,他很友善地回复了我。
他告诉我,事件和操作几乎是等价的,但团队对使用操作的 API 感觉更好。
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.