Error C0020001

本文探讨了在尝试调用托管代码时可能遇到的异常情况,特别是当运行时尚未完成初始化或已经开始关闭时。文章详细解释了几种常见场景,如通过COM对象或已代理的委托从非托管DllMain调用托管代码时的问题,并讨论了Windows消息处理期间可能出现的异常。

You may see an exception with this code, or an HRESULT of this value, when trying to call into managed code.  This can happen if you call in before the runtime has finished initializing, or after the runtime has started shutting down.

 

Sometimes it’s obvious how you run into this situation.  For example, if you call into managed code via a COM object or a marshaled delegate from your unmanaged DllMain while processing a DLL_PROCESS_DETACH notification, then it’s quite likely that the runtime has already shut itself down.

 

Other times, it’s not so obvious.  In particular, you might see this exception being raised when a Windows message is being processed by a thread that is pumping messages during shutdown.  If there are still some managed WinProcs registered, then a message might be dispatched to one of them.  When this happens, the runtime will throw the above exception code to indicate that managed execution is no longer possible.  The WinProcs should have been unregistered by code listening to the AppDomain.ProcessExit event (and the AppDomain.DomainUnload event if you have multiple AppDomains in your process).  In the case of WindowsForms, this is handled for you automatically.  But if you are building your own windowing system, this becomes your responsibility.


转载地址:http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51318.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值