RpcMgmtEnableIdleCleanup 在托管代码中的正确用法是什么?

What is the proper usage of RpcMgmtEnableIdleCleanup in managed code?

我正在将 VB6.0 COM 组件现代化为 .Net COM ServicedComponent我注意到原始 VB6.0 组件正在 Class_Terminate 析构函数中调用方法 RpcMgmtEnableIdleCleanup .

Private Sub Class_Terminate()
    Call RpcMgmtEnableIdleCleanup
End Sub

我不确定在现代化过程中是否需要保留这段代码,或者 GC 是否会简单地处理它。

基本上,我的托管代码中需要这个吗?

Protected Overrides Sub Finalize()
    Call RpcMgmtEnableIdleCleanup()
    MyBase.Finalize()
End Sub

我进行了搜索,但没有找到任何与我的问题相关的内容。

看起来像巫毒编程。人们想象你在程序的开始而不是结束时这样做。

只能开不能关。它可以根据系统决定打开或关闭。系统会在必要时开启它。

我会说这与程序无关,而是与系统管理有关。如果它解决了特定版本的问题,那么原因早已不复存在。

这是帮助的备注。

Remarks

Note RpcMgmtEnableIdleCleanup is a Microsoft extension to the OSF-DCE RPC specification.

Calling this function only is sufficient. Once called, idle resource cleanup cannot be turned off. In some cases, depending on Windows version and configuration, RPC Runtime may need to create a separate thread in order to perform such cleanup, which is why idle resource cleanup is not always turned on. On Windows XP and later versions of Windows, RPC Runtime is programmed to automatically turn on idle resource cleanup if idle resources reach a certain threshold.