Windows Azure 角色中的 OnStop() 方法和 Stopping 事件有什么区别?
每当 Windows Azure 角色停止时,都会调用其 OnStop()
方法。事实证明,有 RoleEnvironment.Stopping<在调用
OnStop()
之前触发的 /code> 事件。 MSDN 表示此事件是角色干净关闭代码的正确位置。
两者有什么区别?为什么我要将角色干净关闭代码放在 Stopping
事件中而不是放在 OnStop()
方法重写中?
Whenever a Windows Azure role is stopped its OnStop()
method is invoked. Turns out that there's RoleEnvironment.Stopping
event that is triggered before OnStop()
is invoked. MSDN says this event is the right place for role clean shutdown code.
What's the difference between the two? Why would I put role clean shutdown code in Stopping
event and not in OnStop()
method override?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了事件机制提供了一种灵活的方式来附加处理程序之外,而
OnStop
方法必须直接在从RoleEntryPoint
派生的类上定义,一个相关的区别是:因此,例如,当为来宾操作系统升级而重新启动虚拟机时,不会引发停止事件。
另一个区别是:
虽然文档中没有提到 Stopping 事件有这样的限制。
来源:
Besides the fact that the event mechanism provides a flexible way to attach handlers, while the
OnStop
method has to be defined directly on the class derived fromRoleEntryPoint
, one relevant difference is this:So the stopping event will not be raised, for instance, when the VM is rebooted for guest OS upgrade.
Another difference is this:
While there is no mention in the documentation that the Stopping event has such a limit.
Source:
事件允许其他类中的其他订阅者执行某些操作,而该方法允许子类作者(例如您自己)将其放置在实际类中并(例如)修改引发哪些事件。
Events allow other subscribers in other classes to perform some action, whereas the method allows the subclass author such as yourself to place it in the actual class and (for example) modify which events get raised.
Brent Stineman(Windows Azure MVP)最近 博客介绍了 RoleEntryPoint 和相关的启动/运行/停止序列,并在序列描述中描述了 Stopping 和 OnStop。
Brent Stineman (Windows Azure MVP) recently blogged about the RoleEntryPoint and related start/run/stop sequence, and describes both Stopping and OnStop in the sequence descriptions.