I am currently developing software which I would like while the software is installing, it can create the native images for the software in the background.
I am thinking of using NGEN and also set the process priority to low because I don't want it to consume 100% CPU. But I found out the ".NET Runtime Optimization Service" is actually missing from the "Services" on my computer. So NGEN won't actually continue all my process even when the computer is in "idle".
I just wonder is there any way I can re-register the service or are there any solutions for it?
I've checked the NGEN service on my Win10 machine and found only .NET Runtime Optimization Service v2.0.50727_X86
for old .NET 2.0/3.5, there is no service for .NET 4.x. But I found a couple of scheduled tasks in Task Scheduler Library/Microsoft/Windows/.NET Framework
This article and optimization script will help to figure the problem out. It seems, that for Win8 and later MS developers are using the task instead of service to run queued native image generation
var drainAppStoreQueue = function () {
var schTasks = wsh.ExpandEnvironmentStrings("%windir%\\System32\\schtasks.exe");
var arguments = "/run /Tn \"\\Microsoft\\Windows\\.NET Framework\\.NET Framework NGEN v4.0.30319";
runToCompletion(schTasks, arguments + "\"", true);
if (is64bit)
runToCompletion(schTasks, arguments + " 64\"", true);
}
drainNGenQueue(isV4Installed ? "v4.0.30319" : "v2.0.50727");
if (isOSWin8OrLater) {
drainAppStoreQueue();
}
I've tried to get a status of ngen service for both x86/x64 .NET Framework version and it reports
C:\Windows\Microsoft.NET\Framework\v4.0.30319>ngen queue status
Microsoft (R) CLR Native Image Generator - Version 4.8.3752.0 Copyright (c) Microsoft Corporation. All rights reserved.
Service name is: .NET Framework NGEN v4.0.30319 The .NET Runtime Optimization Service is stopped.
As I understood, it'll start when action is queued for the scheduled execution. According to ngen reference, you have a two options:
ngen install [assemblyName | assemblyPath]
to install the
assemblies immediately and synchronously (and will take a time, but
you run it directly) /queue[:{1|2|3}]
, to make the image generation is scheduled (immediately or in idle time, depending on priority)You can also test that tasks above are working by running ngen update /queue
. Per documentation
If /queue is specified, the updates are queued for the native image service. Updates are always scheduled at priority 3, so they run when the computer is idle.
In my machine this command set the status of .NET Framework NGEN v4.0.30319
task to Queued and updates Last Run Time. You can always excute all scheduled actions synchronously by invoking ngen executeQueuedItems
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With