When I started my Windows 10 PC this afternoon, I found it almost unresponsive. I waited for a few seconds but it was busy doing something in the background. In order to find out what is going on, I launched the Task Manager using the hotkey Ctrl+Shift+Esc and I found that “.NET Runtime Optimization Service” was using the CPU almost to the maximum level.
This is actually a necessary Windows service and it helps the .NET apps run faster on your PC. But why is it using the CPU so much? According to Microsoft, this service is run only after a Windows update or when .NET framework is updated to a new version. Only on those events, it is run to optimize .NET components to run at an optimal level on your PC. This has to be done on all computers individually.
So how do we fix this problem? We cannot disable it because it is a necessary Windows service. The only thing we can do is that we can make run the task faster and be done with it quicker. When this task is run through the service it is run slowly, but when it is run by the admin, everything is done faster.
In order to optimize .NET runtime manually, you can do the following:
- Press Win+X to open the power user menu and select Command Prompt (Admin) from there.
- In the command prompt enter, CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319
Of course, if you are using the 32-bit version of Windows 10, then you should replace Framework64 to Framework.
- After this enter ngen executeQueuedItems in the command prompt and wait for the process to be finished. It is going to take only a few minutes.
If you are unable to follow these instructions then you can download the DrainNGENQueue.ps1 PowerShell script and execute it on your Windows PC. It will automatically run everything required and rush the .NET runtime optimization tasks.