IProcessInitializer 接口


支持 COM 组件启动或关闭时可调用的方法。Supports methods that can be called when a COM component starts up or shuts down.

public interface class IProcessInitializer
public interface IProcessInitializer
type IProcessInitializer = interface
Public Interface IProcessInitializer


如果要在服务器进程(Dllhost.exe)启动或关闭时运行初始化或关闭代码,请在服务组件上实现 IProcessInitializer 接口方法。Implement the IProcessInitializer interface methods on serviced components if you want to run initialization or shutdown code when a server process (Dllhost.exe) starts up or shuts down, respectively.

当 Dllhost.exe 开始和结束时,COM + 提供 StartupShutdown 事件。COM+ provides Startup and Shutdown events when Dllhost.exe starts and ends. 此功能启用 COM + 服务器应用程序中安装的任何 COM + 组件(此处为服务器组件),以运行自定义初始化并清理代码。This feature enables any COM+ components that are installed in a COM+ server application (referred to as server components hereafter) to run custom initialization and clean up code. 在进程的持续时间内,将创建并存储实现 IProcessInitializer 接口的每个组件的实例。An instance of each component that implements the IProcessInitializer interface will be created and stored for the duration of the process. ServicedComponent上实现时,组件集合中的 COMAdminCatalogObject 中的 InitializesServerApplication 参数需要在组件注册过程中设置为 true,以便在启动和关闭过程中调用接口方法。When implemented on a ServicedComponent, the InitializesServerApplication parameter in the COMAdminCatalogObject within the Components collection needs to be set to true during registration of the component, in order for the interface methods to be called during startup and shutdown.

使用 StartupShutdown 事件,可以初始化资源、创建连接、初始化共享数据以及运行清理代码。Using the Startup and Shutdown events, you can initialize resources, create connections, initialize shared data, and run cleanup code. 但是,您不能访问特定于 COM + 的状态,因为尚未创建服务器组件的实例。However, you must not access states that are specific to COM+ because instances of server components have not yet been created. 此外,"Startup" 和 "Shutdown" 事件中的代码应尽可能快地返回,因为系统在系统启动进程后,Dllhost.exe 仅等待90秒,以接受激活。In addition, the code in the Startup and Shutdown events should return as quickly as possible, because the system waits only 90 seconds for Dllhost.exe to prepare to accept activations after the system starts the process. 如果 Dllhost.exe 在90秒内未发出信号,则系统将结束进程;因此,所有初始化处理都需要在此时间范围内完成。If Dllhost.exe does not signal that it is ready within 90 seconds, the system ends the process; thus, all initialization processing needs to be completed within this time frame. 参与初始化的每个服务器组件都必须支持 IProcessInitializer 接口。Each server component that participates in initialization must support the IProcessInitializer interface. 在 Dllhost.exe 启动时,COM + 会创建请求该服务的所有服务器组件,调用 IProcessInitializer 接口 QueryInterface,并调用 Startup 函数。On DllHost.exe startup, COM+ creates all server components that requested this service, calls QueryInterface for the IProcessInitializer interface, and calls the Startup function. 同样,当 Dllhost.exe 进程关闭时,它将对这些以前存储的接口指针调用 Shutdown 函数。Similarly, when the DllHost.exe process is shut down, it calls the Shutdown function on those previously stored interface pointers.



执行关闭操作。Performs shutdown actions. 关闭 Dllhost.exe 时被调用。Called when Dllhost.exe is shut down.


在启动时执行初始化。Performs initialization at startup. 启动 Dllhost.exe 时被调用。Called when Dllhost.exe is started.