ngen.exe high cpu windows 10 - Assemblies Uninstall Endless Loop

11

7

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

Posted 2016-09-19T19:59:03.160

Reputation: 213

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 – 2016-09-19T20:11:49.820

Verify what is going on exactly by using Process Explorer. – Ramhound – 2016-09-19T20:19:25.163

If you are not going to update your question I can't help. – Ramhound – 2016-09-19T21:09:45.537

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 – 2016-09-19T21:28:49.360

The old question is not closed though.... – Ramhound – 2016-09-19T22:01:13.993

re: old question closed - I updated my question to reflect that its not closed. Do you have any further insights? things to try? – Viktor – 2016-09-19T23:13:38.457

Already supplied lots of ideas .... heard nothing constructive....so just leaving Good Lick – Ramhound – 2016-09-19T23:42:53.363

Answers

6

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.

magicandre1981

Posted 2016-09-19T19:59:03.160

Reputation: 86 560

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 – 2016-09-21T00:03:16.447

Hi, I'm still getting out of memory when running this (8 GB RAM). Any suggestions ? – Jalal El-Shaer – 2017-03-08T06:41:38.900

@JalalEl-Shaer ask your own question. I see no relationship between your memory issues and this ngen.exe cpu usage – magicandre1981 – 2017-03-08T16:39:45.020

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 – 2017-11-07T14:14:21.827

3@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 – 2017-11-07T16:45:46.350

So it is possible to use ngen install /queue xxxx and then call ngentask /Runtimewide to force the recreation of the native images? This could come in handy when Device Guard is enabled/disabled which will then lead to CodeIntegrity violations and prevent loading of Ngen images. Then I need a reliable way to regenerate the Ngen images. – Alois Kraus – 2019-12-03T14:51:13.233

I always run this update /force after installing .net updates for Windows 10. – magicandre1981 – 2019-12-03T15:50:01.853

1

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/

user438199

Posted 2016-09-19T19:59:03.160

Reputation: 11