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.

  • I assume you have allowed the procedure to finish what its doing? The question you linked to isn't closed. "NGEN is the native code generator for the dotnet framework. it will churn away as a background task until the native assemblies have been generated" - You can do this manually if you want. – Ramhound Sep 19 '16 at 20:11
  • Verify what is going on exactly by using Process Explorer. – Ramhound Sep 19 '16 at 20:19
  • If you are not going to update your question I can't help. – Ramhound Sep 19 '16 at 21:09
  • I updated the question and also updated the point saying that the old discussion was closed . Also put in the Process Explorer command lines. Also am testing an idea. I didn't allow the procedure to finish what its doing this time because it keeps starting and restarting. – Viktor Sep 19 '16 at 21:28

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 a ot of time and does all pending ngen operations. After this the ngen queue is empty and you shouldn't see the other tasks again.

  • I ran a full NGEN as you instructed. I'm happy to report that I left my computer - went to lunch and came back and my CPU wasn't at 100% for the first time in weeks! Thank you! – Viktor Sep 21 '16 at 0:03
  • Hi, I'm still getting out of memory when running this (8 GB RAM). Any suggestions ? – Jalal El-Shaer Mar 8 '17 at 6:41
  • @JalalEl-Shaer ask your own question. I see no relationship between your memory issues and this ngen.exe cpu usage – magicandre1981 Mar 8 '17 at 16:39
  • No offence intended but is it really ok to post bat scripts to stack exchange websites and ask people to run them as administrators? – pijemcolu Nov 7 '17 at 14:14
  • 2
    @pijemcolu why is this an issue for you? open it in editor and you see it calls "%windir%\Microsoft.NET\Framework\v4.0.30319\ngen.exe" update /force entering a number is easier compared to remember this long command * facepalm* – magicandre1981 Nov 7 '17 at 16:45

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/

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.