Windows Azure 角色中的 OnStop() 方法和 Stopping 事件有什么区别?

发布于 2024-12-17 13:32:56 字数 425 浏览 0 评论 0原文

每当 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

完美的未来在梦里 2024-12-24 13:32:56

除了事件机制提供了一种灵活的方式来附加处理程序之外,而 OnStop 方法必须直接在从 RoleEntryPoint 派生的类上定义,一个相关的区别是:

The Stopping event is not raised when the virtual machine of the role
instance is rebooted.

因此,例如,当为来宾操作系统升级而重新启动虚拟机时,不会引发停止事件。

另一个区别是:

Code running in the OnStop method has 5 minutes to finish when it is called
for reasons other than a user-initiated shutdown.

虽然文档中没有提到 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 from RoleEntryPoint, one relevant difference is this:

The Stopping event is not raised when the virtual machine of the role
instance is rebooted.

So the stopping event will not be raised, for instance, when the VM is rebooted for guest OS upgrade.

Another difference is this:

Code running in the OnStop method has 5 minutes to finish when it is called
for reasons other than a user-initiated shutdown.

While there is no mention in the documentation that the Stopping event has such a limit.

Source:

魔法少女 2024-12-24 13:32:56

事件允许其他类中的其他订阅者执行某些操作,而该方法允许子类作者(例如您自己)将其放置在实际类中并(例如)修改引发哪些事件。

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.

Saygoodbye 2024-12-24 13:32:56

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文