每当我让我的计算机闲置几分钟后,我的进程资源管理器就会显示“ngen.exe”正在运行并占用了我的 4 个 CPU 中的 2 个。
问题:有没有办法将 NGEN.exe 作为后台任务关闭?
我希望(互联网上许多其他人也一样)一次性编译所有 .net 二进制文件,而不是每次我让计算机闲置时都“自动”编译。我查看了整个 Microsoft 论坛,到目前为止,没有人能完全解决此问题,而且许多人都遇到了同样的问题。
显然,.net 框架中的某些库需要重新编译,它会“卡住”并使 CPU 处于高位并一遍又一遍循环。
我刚刚遇到了同样的问题,还有另一个帖子尝试回答,但不完整
/HKLM/SOFTWARE/Microsoft/Windows/Current Version/RUN 的 Regedit 没有用于运行 .net 编译器的条目。一定是有其他原因导致 ngen.exe 触发。
有人可以发布可能触发此功能运行的其他位置吗?
我想关闭它,我相信很多人也会这么做。我还禁用了 Windows 10 中的自动更新。
更新:进程资源管理器显示正在运行的内容:
“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe”卸载“C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\Microsoft.Vf9a08577#\328b1bc4205c08821860805bf5e6c99e\Microsoft.VisualStudio.Tools.Applications.Hosting.ni.dll”/noroot /LegacyServiceBehavior – Viktor 5 分钟前
“C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe”卸载“C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\PresentationFramewo#\7fa93028119b98117acfd5ea18f15c13\PresentationFramework.ni.dll”/noroot /LegacyServiceBehavior – Viktor 4 分钟前编辑
“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe”卸载“C:\WINDOWS\assembly\NativeImages_v2.0.50727_64\Microsoft.PowerShel#\23dfb41f48958215c80bbbc0c9177cb2\Microsoft.PowerShell.Commands.Utility.ni.dll”/noroot /LegacyServiceBehavior
它不断地运行。- 这是 Process explorer 的输出。这非常烦人,而且似乎每次我离开办公桌时都会发生这种情况。
问题:这些似乎是合法的进程。有谁知道怎样手动删除这些卸载命令并一次性完全编译 .net 框架,而不是一遍又一遍地循环?
当前测试:我终止了该进程,然后 ngentask.exe 转到 Windows\assembly 并将这些 Native Image 文件夹移至临时目录。如果它重新启动,我会通知您。如果 NativeImages 文件夹丢失,它可能不会尝试继续卸载这些程序集。
答案1
下载 Easy NGEN 脚本,以管理员身份运行它并选择选项 1 执行完整的 ngen 运行:
这需要花费大量时间并执行所有待处理的 ngen 操作。此后,ngen 队列为空,您不应该再看到其他任务。
(如果链接不起作用,请将代码复制并粘贴到txt文件中并将其重命名为cmd):
@echo off
title Easy Ngen Runner v5 for '.NET 4.x series' by Burf
"%windir%\system32\reg.exe" query "HKU\S-1-5-19" >nul 2>&1 && (
goto :admincheckok
) || (
echo -------
echo *** WARNING ***
echo -------
echo.
echo.
echo ADMINISTRATOR PRIVILEGES NOT DETECTED!
call :line
echo.
echo.
echo This script must be run with administrator privileges!
echo.
echo To do so, right click on this script and select 'Run As Administrator'
echo.
goto :fin
)
:admincheckok
"%windir%\system32\reg.exe" query "hklm\software\microsoft\Windows NT\currentversion" /v buildlabex >"%temp%\os.txt"
find /i "AMD64" <"%temp%\os.txt">nul
if %errorlevel% equ 0 (set arch=x64) else (set arch=x86)
for /f "tokens=3* delims= " %%G in ('reg query "hklm\software\microsoft\Windows NT\currentversion" /v productname') do (set winv=%%G %%H)
echo %winv%|find /i "Windows 10" >nul
if errorlevel 0 (set w10=1&for /f "tokens=3" %%G in ('reg query "hklm\software\microsoft\Windows NT\currentversion" /v UBR') do (set /a UBR=%%G))
if defined w10 (for /f "skip=2 tokens=3,4,6,7 delims=. " %%G in ('type "%temp%\os.txt"') do (set "win=%winv% %arch% Build %%G.%UBR% {%%I %%J}")
) else (
for /f "skip=2 tokens=3,4,6,7 delims=. " %%G in ('type "%temp%\os.txt"') do (set "win=Legacy %winv% %arch% Build %%G.%%H {%%I %%J}")
)
del "%temp%\os.txt"
if not exist "%windir%\Microsoft.NET\Framework\v4.0.30319" goto :notinstalled
:menu
call :title
echo.
echo 1. Run full Ngen 'update' task
echo.
echo 2. Run standard Ngen 'update' task
echo.
echo 3. Execute queued Ngen items (what Windows does in background)
echo.
echo 4. Visit the 'homepage' of Burf:
echo (http://1drv.ms/1oVTfju)
echo.
echo 5. Information
echo.
echo 6. Exit
echo.
echo.
echo.
choice /c 123456 /N /M "Please enter your selection> "
if errorlevel 6 goto :eof
if errorlevel 5 goto :info
if errorlevel 4 start http://1drv.ms/1oVTfju&goto :menu
if errorlevel 3 goto :ngub
if errorlevel 2 goto :ngus
if errorlevel 1 goto :nguf
:info
call :title
echo This script allows your to easily run the .NET Framework tool Ngen
echo (Native Image Generator) program.
echo.
echo The three options in the menu represent the three different methods in
echo which is can be run:
echo Menu option 1 - Recreates all images
echo Menu option 2 - Processes images that have become invalid
echo Menu option 3 - Execute items already in queue to be processed by Windows
echo.
echo Option 1 is really only beneficial after a .NET Framework or a major Windows
echo update has been installed. Option 3 executes those items already in the
echo queue, this just processes the items immediately instead of during idle
echo processor time.
echo.
echo Option 2 should be used for general use, option 1 after a .NET Framework
echo or major Windows update (including Insider Previews), and option 3 is
echo only provided for completeness of this script. It is the 'least useful'.
echo.
echo It makes sense to have queued items processed and native images updated
echo before they are actually required!
echo.
echo.
echo Press any key to return to menu...
pause >nul
goto :menu
:nguf
call :title
echo Running x86 update item task. Some 'errors' may show, this is expected.
call :line
echo.
"%windir%\Microsoft.NET\Framework\v4.0.30319\ngen.exe" update /force
if defined task (
"%windir%\Microsoft.NET\Framework\v4.0.30319\ngentask.exe" /runtimewide
)
echo.
if %arch% equ x86 (goto :nudone)
echo.
echo Now running x64 update item task. Some 'errors' may show, this is expected.
call :line
echo.
"%windir%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" update /force
if defined task (
"%windir%\Microsoft.NET\Framework64\v4.0.30319\ngentask.exe" /runtimewide
)
goto :nudone
:ngus
call :title
echo Running x86 update item task. Some 'errors' may show, this is expected.
call :line
echo.
"%windir%\Microsoft.NET\Framework\v4.0.30319\ngen.exe" update
if defined task (
"%windir%\Microsoft.NET\Framework\v4.0.30319\ngentask.exe" /runtimewide
)
echo.
if %arch% equ x86 (goto :nudone)
echo.
echo Now running x64 update item task. Some 'errors' may show, this is expected.
call :line
echo.
"%windir%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" update
if defined task (
"%windir%\Microsoft.NET\Framework64\v4.0.30319\ngentask.exe" /runtimewide
)
goto :nudone
:ngub
call :title
echo Running x86 update item task. Some 'errors' may show, this is expected.
call :line
echo.
"%windir%\Microsoft.NET\Framework\v4.0.30319\ngen.exe" executequeueditems
if defined task (
"%windir%\Microsoft.NET\Framework\v4.0.30319\ngentask.exe" /runtimewide
)
echo.
if %arch% equ x86 (goto :nudone)
echo.
echo Now running x64 update item task. Some 'errors' may show, this is expected.
call :line
echo.
"%windir%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" executequeueditems
if defined task (
"%windir%\Microsoft.NET\Framework64\v4.0.30319\ngentask.exe" /runtimewide
)
goto :nudone
:nudone
echo.
echo.
echo Done! Please note that some 'errors' may have appeared. These are, for the
echo most part, not unexpected and are not deemed critical.
echo.
goto :fin
:title
cls
echo -----------------------------------------
echo Easy Ngen Runner v5 for '.NET 4.x' series by Burf
echo -----------------------------------------
echo %win%
echo.
goto :eof
:fin
echo.
echo Press any key to exit...
pause >nul
goto :eof
:notinstalled
echo Microsoft .NET Framework 4, 4.5, 4.6, or 4.7 NOT detected. Please install before
echo using this script. If already installed, something may be 'wrong'...
goto :fin
:line
echo ____________________________________________________________________________
goto :eof
答案2
删除注册表中的一个键对我来说终于有用了。问题是 ngen 会尝试一遍又一遍地为注册表中同一个损坏的 DLL 重新分配内存。它最终会用尽计算机上所有可用的内存。
删除键“\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v2.0.50727\NGenService\Roots”对我有用。停止计划任务或终止 ngen.exe 只是一种临时措施,并不能解决问题。
我无法理解微软怎么会让这样的问题持续这么久。今天是我第一次通过搜索找到答案。
有关此问题的更多信息可以在这里找到https://aloiskraus.wordpress.com/2017/12/13/the-case-of-ngen-exe-needing-50-gb-of-memory/
答案3
这个对我有用,我按照网上说的做了,然后运行了病毒扫描,结果马上就出来了,有一个名为 .netframework 的 .dll 文件形式的病毒,结果发现它是一个 CPU 挖掘病毒,希望这对你有帮助