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

每当 Windows Azure角色停止时,都会调用其OnStop()方法.事实证明,在调用OnStop()之前触发了 RoleEnvironment.Stopping event. MSDN说这个事件是角色清理关闭代码的正确位置.

两者有什么区别?为什么我会在Stopping事件中放置角色干净关闭代码而不在OnStop()方法覆盖中?

除了事件机制提供一种灵活的方式来附加处理程序这一事实,而OnStop方法必须直接在从RoleEntryPoint派生的类上定义,一个相关的区别是:
The Stopping event is not raised when the virtual machine of the role
instance is rebooted.

因此,不会引发停止事件,例如,当VM重新引导以进行客户操作系统升级时.

一个区别是:

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

虽然文档中没有提到Stopping事件有这样的限制.

资源:

> MSDN – RoleEnvironment.Stopping Event
> MSDN – RoleEntryPoint.OnStop Method

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...