.NET Runtime Optimization Service(mscorsvw.exe)进程占用CPU过高的问题处理
Joe 于 2021-01-25 18:04:39 发布至 电脑其他 累计 1656 次阅读
今天在更新完VS2019后,发现电脑的CPU被一个进程.NET Runtime Optimization Service(mscorsvw.exe)疯狂占用,居高不下,后面查了下大概知道什么原因了,VS更新后触发了.NET的最佳化服务,会预编译那些高优先级的assemblies,然后等到你的电脑空闲的时候再去处理那些低优先级的assemblies 。一旦它全部处理完毕,它将会终止,不再占用资源,所以这个过程是不定的,不确定他什么时间就开始占用资源,我们可以额使用一个脚本加快这个优化服务。
管理员运行Powershell,执行如下脚本,可加快这个服务的执行进度。
# Script to force the .NET Framework optimization service to run at maximum speed. $isWin8Plus = [Environment]::OSVersion.Version -ge (new-object 'Version' 6,2) $dotnetDir = [environment]::GetEnvironmentVariable("windir","Machine") + "\Microsoft.NET\Framework" $dotnet2 = "v2.0.50727" $dotnet4 = "v4.0.30319" $dotnetVersion = if (Test-Path ($dotnetDir + "\" + $dotnet4 + "\ngen.exe")) {$dotnet4} else {$dotnet2} $ngen32 = $dotnetDir + "\" + $dotnetVersion +"\ngen.exe" $ngen64 = $dotnetDir + "64\" + $dotnetVersion +"\ngen.exe" $ngenArgs = " executeQueuedItems" $is64Bit = Test-Path $ngen64 #32-bit NGEN -- appropriate for 32-bit and 64-bit machines Write-Host("Requesting 32-bit NGEN") Start-Process -wait $ngen32 -ArgumentList $ngenArgs #64-bit NGEN -- appropriate for 64-bit machines if ($is64Bit) { Write-Host("Requesting 64-bit NGEN") Start-Process -wait $ngen64 -ArgumentList $ngenArgs } #AutoNGEN for Windows 8+ machines if ($isWin8Plus) { Write-Host("Requesting 32-bit AutoNGEN -- Windows 8+") schTasks /run /Tn "\Microsoft\Windows\.NET Framework\.NET Framework NGEN v4.0.30319" } #64-bit AutoNGEN for Windows 8+ machines if ($isWin8Plus -and $is64Bit) { Write-Host("Requesting 64-bit AutoNGEN -- Windows 8+") schTasks /run /Tn "\Microsoft\Windows\.NET Framework\.NET Framework NGEN v4.0.30319 64" }