ResourceManager.ReleaseAllResources 方法


告知资源管理对所有 ResourceSet 对象调用方法 Close(),并释放所有资源。Tells the resource manager to call the Close() method on all ResourceSet objects and release all resources.

 virtual void ReleaseAllResources();
public virtual void ReleaseAllResources ();
abstract member ReleaseAllResources : unit -> unit
override this.ReleaseAllResources : unit -> unit
Public Overridable Sub ReleaseAllResources ()


此方法将缩小正在运行的应用程序中的工作集。This method will shrink the working set in a running app. ResourceManager对象将来的任何资源查找都将像第一次查找一样昂贵,因为资源管理器将不得不再次搜索并加载资源。Any future resource lookups on this ResourceManager object will be as expensive as the first lookup, because the resource manager will have to search and load resources again. 这在某些复杂的线程方案中非常有用,在这种ResourceManager情况下,创建新对象是适当的行为。This can be useful in some complex threading scenarios, where creating a new ResourceManager object is the appropriate behavior.


从 .NET Framework 版本2.0 开始,方法在ReleaseAllResources GetObjectGetStringGetStream操作方面不是线程安全的。Starting with the .NET Framework version 2.0, the ReleaseAllResources method is not thread safe with respect to GetObject, GetString, and GetStream operations. 此更改的优点是对访问资源的多个线程性能有所提高。The advantage of this change is a performance improvement for multiple threads that access resources. 但是,如果在一个线程ReleaseAllResources中调用方法同时同时获取另一个线程中的资源,则 get 操作可能会ObjectDisposedException引发异常。However, if you call the ReleaseAllResources method in one thread while simultaneously getting a resource in another thread, the get operation can throw an ObjectDisposedException exception.

你还可以在以下情况下使用此方法:当前资源管理器创建的资源的托管实例必须以确定性方式释放,无需等待资源管理器完全超出范围并进行垃圾回收。You can also use this method in situations where the managed instances for the resources created by the current resource manager have to be released deterministically, without waiting for the resource manager to go completely out of scope and be garbage collected.


调用此方法不会卸载附属程序集。Calling this method does not unload satellite assemblies. 若要卸载附属程序集, Unload请使用方法。To unload satellite assemblies, use the Unload method .


当通过诸如InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])等机制后期绑定调用时。when invoked late-bound through mechanisms such as InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]). 关联枚举:MemberAccessAssociated enumeration: MemberAccess.