It is very important to optimize everything possible for BizTalk to achieve the best performance it can, especially if you are dealing with BizTalk Server DEV environments on Azure using Azure Virtual Machines. Again, as I explain in a previous post (here), we normally tend to be careful in choosing the VM Disk type and VM sizes mostly because of the price, so tuning the machine is very important, otherwise sometimes they tend to be a little slow and even the most insignificant things (that we think they are) can have a huge impact on BizTalk Server performance. One of the cases I found recently was the .NET Runtime Optimization Service causing high CPU usage…
… Indeed, and we don’t need to give explanations to explain that everything that may affect the CPU to cause a High Load (or usage) inherently affects and cause huge impact on BizTalk Server performance.
📝 One-Minute Brief
A BizTalk assessment troubleshooting guide that explains why the .NET Runtime Optimization Service can suddenly cause high CPU usage on BizTalk Server machines and how to identify, understand, and safely mitigate its impact during performance incidents.
The .NET Framework is regularly optimized by Microsoft using the .NET Runtime Optimization Service to ensure you get the best out of the system libraries, and this is also done for your installed managed applications. It is also responsible, to some extent, for precompiling .NET assemblies in the background. Once it’s done, it will go away. And while you may see CPU usage almost near the 100%, the compilation happens in a process with low priority, so it tries not to steal the CPU from other processes you are running. Once everything is compiled, assemblies will now be able to share pages across different processes, and warm startup will typically be much faster.
Again, once the .NET Runtime Optimization Service finishes its process, it will go away. In my case, this process had already been running for several hours, so instead of waiting until the computer idles, we can force it to compile everything now! Solving this “issue” in a fast way (a couple of minutes). For that, you should:
- Open a command prompt as administrator and run the adsutil command. To do this, press the Windows key to open the Start menu, type cmd in the Start Search box, right-click Command Prompt, and select the Run as administrator option from the context menu.
- And change to the following folder: C:\Windows\Microsoft.NET\Framework\v4.0.30319 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ (on a 64-bit operating system).
- Type ngen.exe executequeueditems, and press ENTER.
- Wait until the operation is finished. I think you may receive the following message at the command prompt: All compilation targets are up to date.
This will process all pending work. Once this is done, the service will shut down because it has nothing else to do, and you will see the CPU return to normal.
This can be important to be aware for the Administration team (or DevOps team) while planning your .NET framework update to make sure that everything runs smoothly, especially in the production environment, otherwise this can be one of the reasons (at least for a few minutes or hours) for you to notice that our production applications are running a little slowly.
There is also a PowerShell provided by the Microsoft .NET team to speed up the optimization service: DrainNGenQueue.ps (see more here).
Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son.


Thank you so much.. got this bug after recent updates..
Thanks for the tip. Worked.
Also worth mentioning that these KB’s cause the issue
.Net framework update
OS version
KB4338420
Windows Server 2008
KB4338606
Windows Server 2008 R2
KB4054542
Windows Server 2012
KB4054566
Windows Server 2012 R2
KB4054590
KB4338814
KB4338419
KB4338605
KB4345418
Thanks for the update
Thank you for a very helpful tip.
Only such a small fix – in the command window we do not provide the extension .exe
So the command looks like this – “ngen executequeueditems”
A runtime optimization service that takes 100% CPU… Oh, the ironies from Redmond…
Thank you for this article – it helped me out.
nao funcionou nada descrito acima