关于 F# 项目中服务器 GC 的警告

Abh*_*kar 6 f# .net-core

我正在开发我的第一个 F# 项目,并且正在尝试使用 Hopac 库。

我在 Mac 上使用的是 dotnet 版本 3.1.300。我已经使用以下内容初始化了我的项目:

dotnet new console --language F#
dotnet add package Hopac
Run Code Online (Sandbox Code Playgroud)

使用 Hopac 库编写后,按以下方式运行程序:

dotnet run
Run Code Online (Sandbox Code Playgroud)

程序的运行时行为符合我的预期,但我收到以下警告:

警告:您正在使用单线程工作站垃圾收集,这意味着并行程序无法扩展。请配置您的程序以使用服务器垃圾收集。

正如 SO 中的一些线程所建议的,添加以下子句:

<ServerGarbageCollection>true</ServerGarbageCollection>
Run Code Online (Sandbox Code Playgroud)

我在 fsproj 配置中尝试了以下操作:

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
  <ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>


 <PropertyGroup>
   <OutputType>Exe</OutputType>
   <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

 <ItemGroup>
    <Compile Include="Program.fs" />
 </ItemGroup>

 <ItemGroup>
  <PackageReference Include="Hopac" Version="0.4.1" />
 </ItemGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

另外我也尝试过:

<Project Sdk="Microsoft.NET.Sdk">

 <PropertyGroup>
   <ServerGarbageCollection>true</ServerGarbageCollection>
   <OutputType>Exe</OutputType>
   <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

 <ItemGroup>
    <Compile Include="Program.fs" />
 </ItemGroup>

 <ItemGroup>
  <PackageReference Include="Hopac" Version="0.4.1" />
 </ItemGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

但同样的警告仍然存在。我在 .NET 配置文件方面绝对是新手,所以我是否犯了一些明显的错误?谢谢

Koe*_*ear 1

在项目的根目录创建一个runtimeconfig.template.json

{
      "configProperties": {
        "System.GC.Server": true
     }

}
Run Code Online (Sandbox Code Playgroud)

要验证是否正常工作,请在代码中打印:

printfn "%A" System.Runtime.GCSettings.IsServerGC
Run Code Online (Sandbox Code Playgroud)

这应该是真的。

由于某种原因,该设置的 SDK 版本不起作用。