IMsoComponent 支持为选择加入

进行了更改,以避免 Windows 窗体线程始终使用现有 IMsoComponentManager 实例注册。 但是,可以选择向 Windows 窗体线程注册现有 IMsoComponentManager 实例。

引入的版本

.NET 9 预览版 2

旧行为

以前,Windows 窗体线程始终使用现有 IMsoComponentManager 实例注册。

新行为

从 .NET 9 开始,Windows 窗体线程不会自动与进程注册的 IMsoComponentManagers 集成。 若要返回以前的行为,请设置开关 Switch.System.Windows.Forms.EnableMsoComponentManager

更改类别

此更改为行为变更

更改原因

进行此更改是为了提高性能和效率。 以前的行为在使用 COM 时会产生很多开销,并非所有开发人员都需要此行为。

如果要还原到以前的行为,可以选择使用 IMsoComponent 文件中的开关或用作项目文件中的 项的 RuntimeHostConfigurationOption 支持。

runtimeconfig.json 文件:

{
  "configProperties": {
    "Switch.System.Windows.Forms.EnableMsoComponentManager": true
 }
}

项目文件:

<ItemGroup>
  <RuntimeHostConfigurationOption Include="Switch.System.Windows.Forms.EnableMsoComponentManager" Value="true" />
</ItemGroup>

受影响的 API