18

Whenever I leave my computer idle for a few minutes I come back and my Process Explorer shows that 'ngen.exe' is running and occupying 2 of my 4 cpus.

Question: Is there a way to turn NGEN.exe off as a background task?

I'd like to (as do many others on the internet) compile all the .net binaries all at once instead of having the computer 'automatically' doing so every time I leave the computer idle. I've checked throughout Microsoft forums and so far nobody has a complete answer to this problem, and many are having the same issues.

Apparently some library in .net framework is needing to be recompiled and it gets 'stuck' and puts the CPU into high and loops over and over again.

I've just experienced this same issue and there is another thread attempts to answer it but it is incomplete

Regedit of /HKLM/SOFTWARE/Microsoft/Windows/Current Version/RUN has no entry to run the .net compiler. Something else must be causing ngen.exe to trigger.

Can someone post other locations that might be triggering this to run?

I'd like to turn it off as I'm sure many others would. I also disabled automatic updates in Windows 10.

UPDATE: Process explorer says this is what is running:

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" uninstall "C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\Microsoft.Vf‌​9a08577#\328b1bc4205‌​c08821860805bf5e6c99‌​e\Microsoft.VisualSt‌​udio.Tools.Applicati‌​ons.Hosting.ni.dll" /noroot /LegacyServiceBehavior – Viktor 5 mins ago

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe" uninstall "C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Presentation‌​Framewo#\7fa93028119‌​b98117acfd5ea18f15c1‌​3\PresentationFramew‌​ork.ni.dll" /noroot /LegacyServiceBehavior – Viktor 4 mins ago edit

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe" uninstall "C:\WINDOWS\assembly\NativeImages_v2.0.50727_64\Microsoft.PowerShel#\23dfb41f48958215c80bbbc0c9177cb2\Microsoft.PowerShell.Commands.Utility.ni.dll" /noroot /LegacyServiceBehavior

It keeps running over and over and over again. - that's the output from Process explorer. Its extremely annoying and it seems to happen EVERY TIME I leave my desk.

QUESTION: it seems like these are legitimate processes. Does anyone know a way to manually remove those uninstall commands and compile the .net framework completely 1 time instead of having it loop over and over again?

CURRENTLY TESTING: I killed the process and ngentask.exe then went to Windows\assembly and moved those Native Image folders to a temporary directory. I'll keep you posted if it starts back up again. Chances are if the NativeImages folders are missing it won't try to keep uninstalling those assemblies.

Viktor
  • 295

3 Answers3

11

Download the Easy NGEN Script, run it as admin and select option 1 to do a full ngen run:

enter image description here

This takes alot of time and does all pending ngen operations. After this the ngen queue is empty and you shouldn't see the other tasks again.

(If the link doesn't work, copy and paste the code into a txt file and rename it to 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

Deleting a key in the registry is what finally worked for me. The problem was that ngen would try to keep reallocating memory over and over for the same corrupt DLL in the registry. It would eventually use up all the available memory on the computer.

Deleting the key "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v2.0.50727\NGenService\Roots" worked for me. Stopping the scheduled task or killing ngen.exe is just a temporary measure and doesn't address the problem.

How Microsoft could let a problem like this go on for so long is beyond me. Today was the first day a search resulted in an answer for me.

More information on the problem can be found here https://aloiskraus.wordpress.com/2017/12/13/the-case-of-ngen-exe-needing-50-gb-of-memory/

0

this worked for me i ran a virus scan afte doing ever thing that people said online and it cam back right away there was a virus in the form of a .dll file that had the name .netframework turn out it was a cpu mining virus hope this helps