InstrumentationManager 类
定义
提供方法,用于管理生命周期和管理用于分离式提供程序的模型。Provides methods that manage the lifetime and the model used for decoupled providers.
注意:WMI .NET 库现在视为处于最终状态,且没有可用于会影响这些库的非安全性相关问题的进一步开发、增强或更新。Note: the WMI .NET libraries are now considered in final state, and no further development, enhancements, or updates will be available for non-security related issues affecting these libraries. MI API 应用于所有新的开发。The MI APIs should be used for all new development.
public ref class InstrumentationManager abstract sealed
public static class InstrumentationManager
type InstrumentationManager = class
Public Class InstrumentationManager
- 继承
-
InstrumentationManager
示例
下面的示例演示如何使用发布/撤消模型。The following example demonstrates how to use the publish/revoke model. 创建并发布路由器类的两个实例。Two instances of the router class are created and published. 它们将被吊销。They are later revoked.
public class Sample_InstanceProvider
{
public int Main (string[] args)
{
var r_one = new Router();
r_one.Name = "one";
InstrumentationManager.Publish(r_one);
var r_two = new Router ();
r_two.Name = "two";
InstrumentationManager.Publish(r_two);
// ....
InstrumentationManager.Revoke(r_one);
InstrumentationManager.Revoke(r_two);
return 0;
}
}
在下一个示例中,使用注册的回调方法公开 RouterNew 类。In the next example, the callback method of registration is used to expose the RouterNew class.
public int MainNew(string[] args)
{
InstrumentationManager.RegisterType(typeof(RouterNew));
// ....
InstrumentationManager.UnRegisterType(typeof(RouterNew));
return 0;
}
注解
分离的提供程序由应用程序承载。Decoupled providers are hosted by an application. 应用程序可以使用两种方法来使 WMI 类的实例可用:发布/撤消或回调方法。Two methods can be used by the application to make instances of WMI classes available: publish/revoke or the callback method. 回调方法使用 RegisterType 和 UnregisterType 方法。The callback method uses the RegisterType and UnregisterType methods.
在发布/撤消模型中,WMI 基础结构为你需要在回调方法中自行编写的许多方法提供默认行为。In the publish/revoke model, the WMI infrastructure provides default behavior for many of the methods you have to write yourself in the callback method. 其中包括枚举和绑定方法。These include the enumeration and bind methods. 在此模型中,应用程序创建实例并发布它们。In this model, the application creates instances and publishes them. 应用程序负责确保遵守类的键属性。The application is responsible for ensuring that the key properties of the classes are respected. 该应用程序还负责删除实例。The application is also responsible for deleting instances.
在回调模型中,WMI 基础结构要求应用程序具有处理枚举、绑定和实现提供程序功能所需的任何其他方法的方法。In the callback model, the WMI infrastructure expects the application to have methods that handle enumeration, binding and any other methods required to implement the functionality of the provider. 它调用此功能的应用程序,如果它不存在或未正确实现,则会失败。It calls into the application for this functionality and fails if it does not exist or is not implemented properly. 应用程序通过调用将其 WMI 类的类型注册到基础结构, RegisterType 并指示它不再需要通过调用公开的 wmi 类 UnregisterType 。The application registers the type of its WMI classes with the infrastructure by calling RegisterType and indicates that it no longer wants the WMI classes exposed by calling UnregisterType.
方法
| Publish(Object) |
使提供程序实例可用于 WMI 基础结构。Makes an instance of a provider available within the WMI infrastructure. |
| RegisterAssembly(Assembly) |
在 WMI 基础结构中注册程序集。Registers an assembly with the WMI infrastructure. |
| RegisterType(Type) |
在 WMI 基础结构中注册类。Registers a class with the WMI infrastructure. |
| Revoke(Object) |
获取当前可用的提供程序的实例,并使其在 WMI 基础结构中不可用。Takes an instance of a currently available provider and makes it unavailable within the WMI infrastructure. |
| UnregisterAssembly(Assembly) |
对当前在 WMI 基础结构中注册的程序集取消注册。Unregisters an assembly currently registered with the WMI infrastructure. |
| UnregisterType(Type) |
对在 WMI 基础结构中注册的类取消注册。Unregisters a class registered with the WMI infrastructure. |