Prevent .NET Runtime Optimization Service from running on battery?












8















When I opened my laptop this morning, it had rebooted itself (after installing updates). Now the .NET Runtime Optimization Service (ngen?) is using quite a bit of CPU while the computer is on battery. I'm wondering, is there any way to ask Windows to defer these tasks until the laptop is plugged in? I had the laptop plugged in overnight but 30% of my battery is gone after less than an hour of usage, which is not the usual situation.



My computer wasn't idle while it was doing this, so I assume its compiling high-priority assemblies after a .Net Framework update from this article.



I checked the windows update history, and it had installed a cumulative update overnight while plugged in. (https://support.microsoft.com/en-ie/help/4038788/windows-10-update-kb4038788). I wish windows would run .net optimisation as part of that process instead of waiting for me to start using the laptop on battery.



Task Manager










share|improve this question























  • I just saw the same service suddenly eating a lot of CPU and the fan became loud. But in my case it was after I put the computer to sleep after 2 hours of using it. I could not stop the service (either in the window you posted above nore in the detail view). After 5-10 minutes it was over, so I guess it's just a matter of waiting a few minutes

    – hansaplast
    Sep 14 '17 at 20:56
















8















When I opened my laptop this morning, it had rebooted itself (after installing updates). Now the .NET Runtime Optimization Service (ngen?) is using quite a bit of CPU while the computer is on battery. I'm wondering, is there any way to ask Windows to defer these tasks until the laptop is plugged in? I had the laptop plugged in overnight but 30% of my battery is gone after less than an hour of usage, which is not the usual situation.



My computer wasn't idle while it was doing this, so I assume its compiling high-priority assemblies after a .Net Framework update from this article.



I checked the windows update history, and it had installed a cumulative update overnight while plugged in. (https://support.microsoft.com/en-ie/help/4038788/windows-10-update-kb4038788). I wish windows would run .net optimisation as part of that process instead of waiting for me to start using the laptop on battery.



Task Manager










share|improve this question























  • I just saw the same service suddenly eating a lot of CPU and the fan became loud. But in my case it was after I put the computer to sleep after 2 hours of using it. I could not stop the service (either in the window you posted above nore in the detail view). After 5-10 minutes it was over, so I guess it's just a matter of waiting a few minutes

    – hansaplast
    Sep 14 '17 at 20:56














8












8








8


2






When I opened my laptop this morning, it had rebooted itself (after installing updates). Now the .NET Runtime Optimization Service (ngen?) is using quite a bit of CPU while the computer is on battery. I'm wondering, is there any way to ask Windows to defer these tasks until the laptop is plugged in? I had the laptop plugged in overnight but 30% of my battery is gone after less than an hour of usage, which is not the usual situation.



My computer wasn't idle while it was doing this, so I assume its compiling high-priority assemblies after a .Net Framework update from this article.



I checked the windows update history, and it had installed a cumulative update overnight while plugged in. (https://support.microsoft.com/en-ie/help/4038788/windows-10-update-kb4038788). I wish windows would run .net optimisation as part of that process instead of waiting for me to start using the laptop on battery.



Task Manager










share|improve this question














When I opened my laptop this morning, it had rebooted itself (after installing updates). Now the .NET Runtime Optimization Service (ngen?) is using quite a bit of CPU while the computer is on battery. I'm wondering, is there any way to ask Windows to defer these tasks until the laptop is plugged in? I had the laptop plugged in overnight but 30% of my battery is gone after less than an hour of usage, which is not the usual situation.



My computer wasn't idle while it was doing this, so I assume its compiling high-priority assemblies after a .Net Framework update from this article.



I checked the windows update history, and it had installed a cumulative update overnight while plugged in. (https://support.microsoft.com/en-ie/help/4038788/windows-10-update-kb4038788). I wish windows would run .net optimisation as part of that process instead of waiting for me to start using the laptop on battery.



Task Manager







windows-10 laptop windows-update battery .net-framework






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 14 '17 at 0:25









kristianpkristianp

94221018




94221018













  • I just saw the same service suddenly eating a lot of CPU and the fan became loud. But in my case it was after I put the computer to sleep after 2 hours of using it. I could not stop the service (either in the window you posted above nore in the detail view). After 5-10 minutes it was over, so I guess it's just a matter of waiting a few minutes

    – hansaplast
    Sep 14 '17 at 20:56



















  • I just saw the same service suddenly eating a lot of CPU and the fan became loud. But in my case it was after I put the computer to sleep after 2 hours of using it. I could not stop the service (either in the window you posted above nore in the detail view). After 5-10 minutes it was over, so I guess it's just a matter of waiting a few minutes

    – hansaplast
    Sep 14 '17 at 20:56

















I just saw the same service suddenly eating a lot of CPU and the fan became loud. But in my case it was after I put the computer to sleep after 2 hours of using it. I could not stop the service (either in the window you posted above nore in the detail view). After 5-10 minutes it was over, so I guess it's just a matter of waiting a few minutes

– hansaplast
Sep 14 '17 at 20:56





I just saw the same service suddenly eating a lot of CPU and the fan became loud. But in my case it was after I put the computer to sleep after 2 hours of using it. I could not stop the service (either in the window you posted above nore in the detail view). After 5-10 minutes it was over, so I guess it's just a matter of waiting a few minutes

– hansaplast
Sep 14 '17 at 20:56










1 Answer
1






active

oldest

votes


















1














The short answer is no, you cant reliably defer ngen (and you shouldnt try), the only consistent/useful option i found was forcing it to run to completion and not leaving it lurk in the background.



If your trying to save some CPU cycles on battery (or in my case stop a server from running ngen after returning it into service following Windows updates) your best option is to force ngen to run yourself. For a desktop PC, 2 options come to mind:




  1. Create a .bat or .ps1 file on your desktop with appropriate ngen command below - just double click and wait for ngen to close before you unplug. If you create the script in your Windows folder instead and shortcut to it on your desktop you can also use Command or Powershell Prompt or the Run dialog to execute it as required (before you unplug/after an update).


  2. Another option that should work is to use a scheduled task to execute the above script. Run it on startup, without a logged on user, as an Administrator. If your laptop is allowed to install updates overnight and can reboot this should work nicely.



To run ngen you only need one of the following commands, use the first/most appropriate option for your system:




  • .Net 4 or better on 64bit
    C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems


  • .Net 4 or better on 32bit
    C:WindowsMicrosoft.NETFrameworkv4.0.30319ngen.exe executeQueuedItems


  • .Net 3 or less on 64bit
    C:WindowsMicrosoft.NETFramework64v2.0.50727ngen.exe executeQueuedItems


  • .Net 3 or less on 32bit
    C:WindowsMicrosoft.NETFrameworkv2.0.50727ngen.exe executeQueuedItems



Below is the minimal output you get from ngen when there are no queued items:



PS C:UsersAdministrator> C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems
Microsoft (R) CLR Native Image Generator - Version 4.6.1586.0
Copyright (c) Microsoft Corporation. All rights reserved.
All compilation targets are up to date.


When ngen.exe is ran with executeQueuedItems it will force it to perform all pending tasks as quickly as possible. Normally ngen runs on a low priority background thread(and apparently just starts at random), the idea being it shouldnt starve other processes of CPU - though that doesnt always work. Running ngen interactively is quicker than leaving it run in the background - but it will impact performance more. How long it takes depends on your hardware and how many/which native images need recompiling.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1250155%2fprevent-net-runtime-optimization-service-from-running-on-battery%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The short answer is no, you cant reliably defer ngen (and you shouldnt try), the only consistent/useful option i found was forcing it to run to completion and not leaving it lurk in the background.



    If your trying to save some CPU cycles on battery (or in my case stop a server from running ngen after returning it into service following Windows updates) your best option is to force ngen to run yourself. For a desktop PC, 2 options come to mind:




    1. Create a .bat or .ps1 file on your desktop with appropriate ngen command below - just double click and wait for ngen to close before you unplug. If you create the script in your Windows folder instead and shortcut to it on your desktop you can also use Command or Powershell Prompt or the Run dialog to execute it as required (before you unplug/after an update).


    2. Another option that should work is to use a scheduled task to execute the above script. Run it on startup, without a logged on user, as an Administrator. If your laptop is allowed to install updates overnight and can reboot this should work nicely.



    To run ngen you only need one of the following commands, use the first/most appropriate option for your system:




    • .Net 4 or better on 64bit
      C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems


    • .Net 4 or better on 32bit
      C:WindowsMicrosoft.NETFrameworkv4.0.30319ngen.exe executeQueuedItems


    • .Net 3 or less on 64bit
      C:WindowsMicrosoft.NETFramework64v2.0.50727ngen.exe executeQueuedItems


    • .Net 3 or less on 32bit
      C:WindowsMicrosoft.NETFrameworkv2.0.50727ngen.exe executeQueuedItems



    Below is the minimal output you get from ngen when there are no queued items:



    PS C:UsersAdministrator> C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems
    Microsoft (R) CLR Native Image Generator - Version 4.6.1586.0
    Copyright (c) Microsoft Corporation. All rights reserved.
    All compilation targets are up to date.


    When ngen.exe is ran with executeQueuedItems it will force it to perform all pending tasks as quickly as possible. Normally ngen runs on a low priority background thread(and apparently just starts at random), the idea being it shouldnt starve other processes of CPU - though that doesnt always work. Running ngen interactively is quicker than leaving it run in the background - but it will impact performance more. How long it takes depends on your hardware and how many/which native images need recompiling.






    share|improve this answer




























      1














      The short answer is no, you cant reliably defer ngen (and you shouldnt try), the only consistent/useful option i found was forcing it to run to completion and not leaving it lurk in the background.



      If your trying to save some CPU cycles on battery (or in my case stop a server from running ngen after returning it into service following Windows updates) your best option is to force ngen to run yourself. For a desktop PC, 2 options come to mind:




      1. Create a .bat or .ps1 file on your desktop with appropriate ngen command below - just double click and wait for ngen to close before you unplug. If you create the script in your Windows folder instead and shortcut to it on your desktop you can also use Command or Powershell Prompt or the Run dialog to execute it as required (before you unplug/after an update).


      2. Another option that should work is to use a scheduled task to execute the above script. Run it on startup, without a logged on user, as an Administrator. If your laptop is allowed to install updates overnight and can reboot this should work nicely.



      To run ngen you only need one of the following commands, use the first/most appropriate option for your system:




      • .Net 4 or better on 64bit
        C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems


      • .Net 4 or better on 32bit
        C:WindowsMicrosoft.NETFrameworkv4.0.30319ngen.exe executeQueuedItems


      • .Net 3 or less on 64bit
        C:WindowsMicrosoft.NETFramework64v2.0.50727ngen.exe executeQueuedItems


      • .Net 3 or less on 32bit
        C:WindowsMicrosoft.NETFrameworkv2.0.50727ngen.exe executeQueuedItems



      Below is the minimal output you get from ngen when there are no queued items:



      PS C:UsersAdministrator> C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems
      Microsoft (R) CLR Native Image Generator - Version 4.6.1586.0
      Copyright (c) Microsoft Corporation. All rights reserved.
      All compilation targets are up to date.


      When ngen.exe is ran with executeQueuedItems it will force it to perform all pending tasks as quickly as possible. Normally ngen runs on a low priority background thread(and apparently just starts at random), the idea being it shouldnt starve other processes of CPU - though that doesnt always work. Running ngen interactively is quicker than leaving it run in the background - but it will impact performance more. How long it takes depends on your hardware and how many/which native images need recompiling.






      share|improve this answer


























        1












        1








        1







        The short answer is no, you cant reliably defer ngen (and you shouldnt try), the only consistent/useful option i found was forcing it to run to completion and not leaving it lurk in the background.



        If your trying to save some CPU cycles on battery (or in my case stop a server from running ngen after returning it into service following Windows updates) your best option is to force ngen to run yourself. For a desktop PC, 2 options come to mind:




        1. Create a .bat or .ps1 file on your desktop with appropriate ngen command below - just double click and wait for ngen to close before you unplug. If you create the script in your Windows folder instead and shortcut to it on your desktop you can also use Command or Powershell Prompt or the Run dialog to execute it as required (before you unplug/after an update).


        2. Another option that should work is to use a scheduled task to execute the above script. Run it on startup, without a logged on user, as an Administrator. If your laptop is allowed to install updates overnight and can reboot this should work nicely.



        To run ngen you only need one of the following commands, use the first/most appropriate option for your system:




        • .Net 4 or better on 64bit
          C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems


        • .Net 4 or better on 32bit
          C:WindowsMicrosoft.NETFrameworkv4.0.30319ngen.exe executeQueuedItems


        • .Net 3 or less on 64bit
          C:WindowsMicrosoft.NETFramework64v2.0.50727ngen.exe executeQueuedItems


        • .Net 3 or less on 32bit
          C:WindowsMicrosoft.NETFrameworkv2.0.50727ngen.exe executeQueuedItems



        Below is the minimal output you get from ngen when there are no queued items:



        PS C:UsersAdministrator> C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems
        Microsoft (R) CLR Native Image Generator - Version 4.6.1586.0
        Copyright (c) Microsoft Corporation. All rights reserved.
        All compilation targets are up to date.


        When ngen.exe is ran with executeQueuedItems it will force it to perform all pending tasks as quickly as possible. Normally ngen runs on a low priority background thread(and apparently just starts at random), the idea being it shouldnt starve other processes of CPU - though that doesnt always work. Running ngen interactively is quicker than leaving it run in the background - but it will impact performance more. How long it takes depends on your hardware and how many/which native images need recompiling.






        share|improve this answer













        The short answer is no, you cant reliably defer ngen (and you shouldnt try), the only consistent/useful option i found was forcing it to run to completion and not leaving it lurk in the background.



        If your trying to save some CPU cycles on battery (or in my case stop a server from running ngen after returning it into service following Windows updates) your best option is to force ngen to run yourself. For a desktop PC, 2 options come to mind:




        1. Create a .bat or .ps1 file on your desktop with appropriate ngen command below - just double click and wait for ngen to close before you unplug. If you create the script in your Windows folder instead and shortcut to it on your desktop you can also use Command or Powershell Prompt or the Run dialog to execute it as required (before you unplug/after an update).


        2. Another option that should work is to use a scheduled task to execute the above script. Run it on startup, without a logged on user, as an Administrator. If your laptop is allowed to install updates overnight and can reboot this should work nicely.



        To run ngen you only need one of the following commands, use the first/most appropriate option for your system:




        • .Net 4 or better on 64bit
          C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems


        • .Net 4 or better on 32bit
          C:WindowsMicrosoft.NETFrameworkv4.0.30319ngen.exe executeQueuedItems


        • .Net 3 or less on 64bit
          C:WindowsMicrosoft.NETFramework64v2.0.50727ngen.exe executeQueuedItems


        • .Net 3 or less on 32bit
          C:WindowsMicrosoft.NETFrameworkv2.0.50727ngen.exe executeQueuedItems



        Below is the minimal output you get from ngen when there are no queued items:



        PS C:UsersAdministrator> C:WindowsMicrosoft.NETFramework64v4.0.30319ngen.exe executeQueuedItems
        Microsoft (R) CLR Native Image Generator - Version 4.6.1586.0
        Copyright (c) Microsoft Corporation. All rights reserved.
        All compilation targets are up to date.


        When ngen.exe is ran with executeQueuedItems it will force it to perform all pending tasks as quickly as possible. Normally ngen runs on a low priority background thread(and apparently just starts at random), the idea being it shouldnt starve other processes of CPU - though that doesnt always work. Running ngen interactively is quicker than leaving it run in the background - but it will impact performance more. How long it takes depends on your hardware and how many/which native images need recompiling.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 12 at 14:18









        MisterSmithMisterSmith

        2445




        2445






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1250155%2fprevent-net-runtime-optimization-service-from-running-on-battery%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Probability when a professor distributes a quiz and homework assignment to a class of n students.

            Aardman Animations

            Are they similar matrix